Child pages
  • Logging / I18N
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Frameworks used for logging and i18n

  • FR I18N framework (i18n-core component)

    The I18N framework provides in the i18n-slf4j module, a LocalizedLogger class, which should be used everywhere in the code to log messages and?or exceptions.
    The LocalizedLogger class delegates to SLF4J API.

    An SLF4J implementation can be choosed at runtime by providing the appropriate jar in the classpath. In particular, two implementations are used :
  • OpenDJ implementation, used when the opendj-slf4j-adapter jar is included. It delegate to ErrorLogger and DebugLogger classes from OpenDJ server.
    • this implementation is used in the server.
  • java.util.logging implementation, used when the slf4j-jdk14jar is included.
    • this implementation is used in the tools. 

Log levels

A message can be logged using the following levels (provided by SLF4J API and LocalizedLogger class) :

  • error: signals a fatal or non fatal error that requires an action from an administrator
    • corresponds to fatal / error in OpenDJ server 2
  • warning: signals a potential or real issue that does not require immediate action but may need an administrative action later
    • corresponds to warning in OpenDJ server 2 
  • info: a high-level notice
    • corresponds to notice in OpenDJ server 2
  • debug:  informational message 
    • corresponds to info in OpenDJ server 2
  • trace: information needed to debug
    • corresponds to debug in OpenDJ server 2

Log levels and i18n:

  • Messages logged at error, warning, info and debug level must be internationalized.
  • Messages logged at trace level are not internationalized.

Logger and category and message ID

Each logged message has a category. The category is given by the classname  where the message is logged. 

This allow to define a single logger per class, with the classname.

However, in order to have a higher kind of grouping, some pre-defined categories with simple names are also used (eg, CORESYNC, ...)

There is a mapping between packages (information which is included in classnames) and these simple categories. If a class does not map a pre-defined package, then its category is its class name. 

 For example, all classes in the org.forgerock.opendj.server.core package or a sub-package are mapped to the CORE category.

Note that for debug logging in the server (messages logged by {{DebugLogger}} class), the pre-defined categories are NOT used.

I18N messages identification

For i18n messages, there is a way to uniquely identify the messages with two properties :

  • the resource name of the LocalizableMessage.
  • the ordinal of the LocalizableMessage.

Ordinal is extracted from the message name suffix, while resource name corresponds to the resource file containing the messages. 


Code examples

Non-debug (I18N) messages

The category is given by the message :

LocalizedLogger logger = LocalizedLogger.getLocalizedLogger(ERR_ADMIN_CANNOT_GET_LISTENER_BASE.resourceName())); 

To avoid retrieval of logger at each logging point, it is better to use a static variable in class when the category is always the same:

class SomeClass {
  // Only log admin messages in this class
  static final LocalizedLogger logger = LocalizedLogger.getLocalizedLogger(AdminMessages.resourceName()));
  // log at some point
  logger.error(ERR_ADMIN_CANNOT_GET_LISTENER_BASE, arg1, arg2)

Debug messages

The category is the class name:

class SomeClass {
  static final Logger logger = LoggerFactory.getLogger(SomeClass.class);
  // log at some point
  logger.trace("a debug message", arg1, arg2)





  • No labels