The logging framework in NexJ CRM has been upgraded from Log4j version 1 to Log4j version 2 in the 21.12.1.0 release. The syntax for configuring logging has changed, and the table below has been provided to assist with your transition. It is important to review each row item and apply the corresponding changes after upgrading.
|
Task |
Log4j 1 syntax |
Log4j 2 syntax |
|---|---|---|
|
Setting the system property for the configuration file |
Uses the following syntax:
|
Instead, use the following syntax:
|
|
Setting the root logger |
Uses the following syntax:
|
Instead, use the following syntax:
|
|
Property substitution |
Not applicable |
If you have a system property called For example, you can use the following syntax:
|
|
Automatic reconfiguration |
When file reconfiguration was on or off in Log4j 1, it uses the following syntax:
|
File reconfiguration in Log4j 2 is applied using the For example, you can set the interval to 60 seconds using the following syntax:
|
|
Setting a logger
|
Uses the following syntax:
Also, supports the following syntax:
|
Instead, use the following syntax:
For example, use:
Additional examples are provided below:
|
|
Setting an appender |
Uses the following syntax to add an appender to the root logger:
Uses the following syntax to define an appender:
|
To add an appender to the root logger, use the following syntax:
To define an appender, use the following syntax:
|
|
Setting a rolling file appender |
Uses the following syntax to add an appender to the root logger (console appender is also added):
Uses the following syntax to define the type:
Uses the following syntax to set the pattern:
Uses the following syntax to set the maximum file size for the log:
Uses the following syntax to set the file location:
Uses the following syntax to set the maximum number of rollover files:
Supports the following additional options:
|
To add an appender to the root logger, use the following syntax:
To define a type (and also set the name), use the following syntax:
To set a pattern, use the following syntax:
To set a max file size for the log, use the following syntax: If you are adding one or more policies, the first line must be added.
To set a file location, use the following syntax:
To set the max number of rollover files, use the following syntax:
Supports the following additional options:
The following code shows an example:
|
The examples listed above include the “log4j.” prefix, which is used when you are setting system properties through VM arguments. When you are configuring properties using a properties file, you will need to omit this prefix to conform to the standard Log4j 2 syntax.
Additional references
For additional Log4j 2 information, see:
-
Configuration with properties - https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties
-
Property substitution – https://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
Troubleshooting
The common error shown below is caused by Log4j 2 attempting to parse a Log4j 1 property (for example, log4j.logger.nexj.core.rpc=INFO). Log4j 2 expects a token “name” after nexj and is unable to find it.
Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
...
Caused by: nexj.core.util.UncheckedException: err.logger.initFailed
...
Caused by: org.apache.logging.log4j.core.config.ConfigurationException: No name attribute provided for Logger nexj
Logging configuration issues can be evaluated in more detail through the logs by setting the log4j.debug=true property in the application environment file.