Package org.hcjf.log
Class Log
- java.lang.Object
-
- org.hcjf.service.Service<LogPrinter>
-
- org.hcjf.log.Log
-
public final class Log extends Service<LogPrinter>
Static class that contains the functionality in order to maintain and organize a log file with the same records format The log behavior is affected by the following system properties
hcfj_log_path: work directory of the log, by default app work directory
hcfj_log_initial_queue_size: initial size of the internal queue, by default 10000;
hcfj_log_file_prefix: all the log files start with this prefix, by default hcjf
hcfj_log_error_file: if the property is true then log create a particular file for error group only, by default false
hcfj_log_warning_file: if the property is true then log create a particular file for warning group only, by default false
hcfj_log_info_file: if the property is true then log create a particular file for info group only, by default false
hcfj_log_debug_file: if the property is true then log create a particular file for debug group only, by default false
hcfj_log_level: min level to write file, by default "I"
hcfj_log_date_format: date format to show in the log file, by default "yyyy-mm-dd hh:mm:ss"- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLog.LogGroupThis enum contains all the possible groups for the recordsstatic classLog.LogRecordThis class contains all the information to write a record in the log.-
Nested classes/interfaces inherited from class org.hcjf.service.Service
Service.RunnableWrapperComparator, Service.ShutdownStage, Service.StaticServiceThread, Service.ThreadPoolAgent, Service.ThreadPoolAgentMBean
-
-
Field Summary
-
Fields inherited from class org.hcjf.service.Service
SERVICE_LOG_TAG
-
-
Method Summary
Modifier and Type Method Description static voidaddPrinter(LogPrinter printer)This method register a printer.static java.util.UUIDd(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with debug group ("[D]").static java.util.UUIDd(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with debug group ("[D]").static java.util.UUIDe(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with error group ("[E]").static java.util.UUIDe(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with error group ("[E]").static java.lang.IntegergetLogQueueSize()Return the size of the log queue.static java.util.UUIDi(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[I]").static java.util.UUIDin(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[IN]").protected voidinit()Start the log thread.static java.util.UUIDout(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[OUT]").voidregisterConsumer(LogPrinter consumer)This method register a printer.protected voidshutdown(Service.ShutdownStage stage)Only valid with the stage is STARTvoidunregisterConsumer(LogPrinter consumer)Unregister a specific consumer.static java.util.UUIDw(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with warning group ("[W]").static java.util.UUIDw(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with warning group ("[W]").-
Methods inherited from class org.hcjf.service.Service
call, call, fork, fork, fork, fork, getPriority, getServiceName, run, run, shutdownExecutor, systemShutdown
-
-
-
-
Method Detail
-
init
protected void init()
Start the log thread.- Overrides:
initin classService<LogPrinter>
-
shutdown
protected void shutdown(Service.ShutdownStage stage)
Only valid with the stage is START- Overrides:
shutdownin classService<LogPrinter>- Parameters:
stage- Shutdown stage.
-
registerConsumer
public void registerConsumer(LogPrinter consumer)
This method register a printer.- Specified by:
registerConsumerin classService<LogPrinter>- Parameters:
consumer- Printer.- Throws:
java.lang.NullPointerException- If the printer is null.
-
unregisterConsumer
public void unregisterConsumer(LogPrinter consumer)
Description copied from class:ServiceUnregister a specific consumer.- Specified by:
unregisterConsumerin classService<LogPrinter>- Parameters:
consumer- Consumer to unregister.
-
addPrinter
public static void addPrinter(LogPrinter printer)
This method register a printer.- Parameters:
printer- Printer.- Throws:
java.lang.NullPointerException- If the printer is null.
-
d
public static java.util.UUID d(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with debug group ("[D]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
d
public static java.util.UUID d(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with debug group ("[D]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.throwable- Throwable whose message will be printed as part of recordparams- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
i
public static java.util.UUID i(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[I]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
in
public static java.util.UUID in(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[IN]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
out
public static java.util.UUID out(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with info group ("[OUT]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
w
public static java.util.UUID w(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with warning group ("[W]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
w
public static java.util.UUID w(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with warning group ("[W]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.throwable- Throwable whose message will be printed as part of recordparams- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
e
public static java.util.UUID e(java.lang.String tag, java.lang.String message, java.lang.Object... params)Create a record with error group ("[E]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.params- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
e
public static java.util.UUID e(java.lang.String tag, java.lang.String message, java.lang.Throwable throwable, java.lang.Object... params)Create a record with error group ("[E]"). All the places in the messages are replaced for each param in the natural order.- Parameters:
tag- Tag of the recordmessage- Message to the record. This message use the syntax for classFormatter.throwable- Throwable whose message will be printed as part of recordparams- Parameters for the places in the message.- Returns:
- Returns the id assigned to the log record created, this id could be null if the service does not generates any log records
-
getLogQueueSize
public static java.lang.Integer getLogQueueSize()
Return the size of the log queue.- Returns:
- Size of the log queue.
-
-