org.camunda.commons.logging
Class BaseLogger

java.lang.Object
  extended by org.camunda.commons.logging.BaseLogger

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 Summary
protected  String componentId
          the component Id of the logger.
protected  org.slf4j.Logger delegateLogger
          the slf4j logger we delegate to
protected  String projectCode
          the project code of the logger
 
Constructor Summary
protected BaseLogger()
           
 
Method Summary
static
<T extends BaseLogger>
T
createLogger(Class<T> loggerClass, String projectCode, String name, String componentId)
          Creates a new instance of the Logger.
protected  String exceptionMessage(String id, String messageTemplate, Object... parameters)
          Prepares an exception message
protected  String formatMessageTemplate(String id, String messageTemplate)
          Formats a message template
 boolean isDebugEnabled()
           
 boolean isErrorEnabled()
           
 boolean isInfoEnabled()
           
 boolean isWarnEnabled()
           
protected  void logDebug(String id, String messageTemplate, Object... parameters)
          Logs a 'DEBUG' message
protected  void logError(String id, String messageTemplate, Object... parameters)
          Logs an 'ERROR' message
protected  void logInfo(String id, String messageTemplate, Object... parameters)
          Logs an 'INFO' message
protected  void logWarn(String id, String messageTemplate, Object... parameters)
          Logs an 'WARN' message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

BaseLogger

protected BaseLogger()
Method Detail

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.

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


Copyright © 2014 camunda services GmbH. All Rights Reserved.