Package org.camunda.commons.logging
Class BaseLogger
java.lang.Object
org.camunda.commons.logging.BaseLogger
- Direct Known Subclasses:
AssertionsLogger
,CamundaBpmRunLogger
,ConnectLogger
,DmnLogger
,ExceptionLogger
,ExternalTaskClientLogger
,FeelLogger
,HttpLogger
,LdapPluginLogger
,LoggerUtil
,ProcessEngineLogger
,ScalaFeelLogger
,SoapHttpLogger
,SpinLogger
,SpinPluginLogger
,SpringBootProcessEngineLogger
,UtilsLogger
,WebappLogger
Base class for implementing a logger class. A logger class is a class with
dedicated methods for each log message:
public class MyLogger extends BaseLogger { public static MyLogger LOG = createLogger(MyLogger.class, "MYPROJ", "org.example", "01"); public void engineStarted(long currentTime) { logInfo("100", "My super engine has started at '{}'", currentTime); } }The logger can then be used in the following way:
LOG.engineStarted(System.currentTimeMilliseconds());This will print the following message:
INFO org.example - MYPROJ-01100 My super engine has started at '4234234523'
Slf4j
This class uses slf4j as logging API. The class ensures that log messages and exception messages are always formatted using the same template.Log message format
The log message format produced by this class is as follows:[PROJECT_CODE]-[COMPONENT_ID][MESSAGE_ID] messageExample:
MYPROJ-01100 My super engine has started at '4234234523'
- Author:
- Daniel Meyer, Sebastian Menski
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends BaseLogger>
TcreateLogger
(Class<T> loggerClass, String projectCode, String name, String componentId) Creates a new instance of theLogger
.protected String
exceptionMessage
(String id, String messageTemplate, Object... parameters) Prepares an exception messageprotected String
formatMessageTemplate
(String id, String messageTemplate) Formats a message templateboolean
boolean
boolean
boolean
protected void
Logs a message with the specified log level.protected void
Logs a message with the specified log level.protected void
Logs a 'DEBUG' messageprotected void
Logs an 'ERROR' messageprotected void
Logs an 'INFO' messageprotected void
Logs a 'TRACE' messageprotected void
Logs an 'WARN' message
-
Field Details
-
delegateLogger
protected org.slf4j.Logger delegateLoggerthe slf4j logger we delegate to -
projectCode
the project code of the logger -
componentId
the component Id of the logger.
-
-
Constructor Details
-
BaseLogger
protected BaseLogger()
-
-
Method Details
-
createLogger
public static <T extends BaseLogger> T createLogger(Class<T> loggerClass, String projectCode, String name, String componentId) Creates a new instance of theLogger
.- Parameters:
loggerClass
- the type of the loggerprojectCode
- the unique code for a complete project.name
- the name of the slf4j logger to use.componentId
- the unique id of the component.
-
log
Logs a message with the specified log level. If the log level cannot be matched, it defaults to DEBUG.- Parameters:
level
- the log levelid
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
log
protected void log(String level, Level defaultLevel, String id, String messageTemplate, Object... parameters) Logs a message with the specified log level.- Parameters:
level
- the log leveldefaultLevel
- the default log level to use when log level cannot be matchedid
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
logTrace
Logs a 'TRACE' message- Parameters:
id
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
logDebug
Logs a 'DEBUG' message- Parameters:
id
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
logInfo
Logs an 'INFO' message- Parameters:
id
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
logWarn
Logs an 'WARN' message- Parameters:
id
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
logError
Logs an 'ERROR' message- Parameters:
id
- the unique id of this log messagemessageTemplate
- the message template to useparameters
- a list of optional parameters
-
isDebugEnabled
public boolean isDebugEnabled()- Returns:
- true if the logger will log 'DEBUG' messages
-
isInfoEnabled
public boolean isInfoEnabled()- Returns:
- true if the logger will log 'INFO' messages
-
isWarnEnabled
public boolean isWarnEnabled()- Returns:
- true if the logger will log 'WARN' messages
-
isErrorEnabled
public boolean isErrorEnabled()- Returns:
- true if the logger will log 'ERROR' messages
-
formatMessageTemplate
Formats a message template- Parameters:
id
- the id of the messagemessageTemplate
- the message template to use- Returns:
- the formatted template
-
exceptionMessage
Prepares an exception message- Parameters:
id
- the id of the messagemessageTemplate
- the message template to useparameters
- the parameters for the message (optional)- Returns:
- the prepared exception message
-