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

public abstract class BaseLogger extends Object
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] message
 
Example:
 MYPROJ-01100 My super engine has started at '4234234523'
 
Author:
Daniel Meyer, Sebastian Menski
  • Field Details

    • delegateLogger

      protected org.slf4j.Logger delegateLogger
      the slf4j logger we delegate to
    • projectCode

      protected String projectCode
      the project code of the logger
    • componentId

      protected String 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 the Logger.
      Parameters:
      loggerClass - the type of the logger
      projectCode - the unique code for a complete project.
      name - the name of the slf4j logger to use.
      componentId - the unique id of the component.
    • log

      protected void log(String level, String id, String messageTemplate, Object... parameters)
      Logs a message with the specified log level. If the log level cannot be matched, it defaults to DEBUG.
      Parameters:
      level - the log level
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - 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 level
      defaultLevel - the default log level to use when log level cannot be matched
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - a list of optional parameters
    • logTrace

      protected void logTrace(String id, String messageTemplate, Object... parameters)
      Logs a 'TRACE' message
      Parameters:
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - a list of optional parameters
    • logDebug

      protected void logDebug(String id, String messageTemplate, Object... parameters)
      Logs a 'DEBUG' message
      Parameters:
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - a list of optional parameters
    • logInfo

      protected void logInfo(String id, String messageTemplate, Object... parameters)
      Logs an 'INFO' message
      Parameters:
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - a list of optional parameters
    • logWarn

      protected void logWarn(String id, String messageTemplate, Object... parameters)
      Logs an 'WARN' message
      Parameters:
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - a list of optional parameters
    • logError

      protected void logError(String id, String messageTemplate, Object... parameters)
      Logs an 'ERROR' message
      Parameters:
      id - the unique id of this log message
      messageTemplate - the message template to use
      parameters - 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

      protected String formatMessageTemplate(String id, String messageTemplate)
      Formats a message template
      Parameters:
      id - the id of the message
      messageTemplate - the message template to use
      Returns:
      the formatted template
    • exceptionMessage

      protected String exceptionMessage(String id, String messageTemplate, Object... parameters)
      Prepares an exception message
      Parameters:
      id - the id of the message
      messageTemplate - the message template to use
      parameters - the parameters for the message (optional)
      Returns:
      the prepared exception message