Log4j Configuration

Introduction

FNZ Studio uses Apache Log4j 2 as the logging framework. This article describes how Log4j is initialized and configured by FNZ Studio, and how you can modify this configuration.

For more information on Log4j, see the Apache site.

Configuration

The configuration property nm.log4j.initialize determines whether FNZ Studio initializes the Log4j framework on startup. The default value of this property is true.

To disable the Log4j initialization, set this property to false in the server configuration. This can be necessary if some other component of your execution environment already has initialized Log4j, for example your Java application server.

Important note: If you set this property to false, FNZ Studio will not create the log file application.log automatically.

Default Configuration

FNZ Studio has a built-in Log4j configuration file. The file is located on the class path under com/nm/conf/log4j2.properties.

Following is an example configuration showing the most important settings. To download the correct and full logging configuration for your FNZ Studio release from FNZ Studio Composition, go to System Maintenance > Logging > Settings. Right-click on the desired configuration and select Download.

Copy
# report errors to stdout, application.log, and cluster log
rootLogger = ERROR, stdlog, applog, clustertmplog

# set default log level for FNZ Studio to WARN
log4j.logger.com.nm = WARN
log4j.logger.com.appway = WARN

# temporary, in-memory cluster log
# this appender will be replaced with the real cluster log during start-up.
appender.clustertmplog.type = ClusterLogInMemoryAppender
appender.clustertmplog.name = clustertmplog

# console appender for stdout
appender.stdlog.type = Console
appender.stdlog.name = stdlog
appender.stdlog.layout.type = PatternLayout
appender.stdlog.layout.pattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5p [%t] %c - %m%n%throwable

# default FNZ Studio application.log
appender.applog.type = RollingFile
appender.applog.name = applog
appender.applog.fileName = ${nm.data.home}/logs/application.log
appender.applog.filePattern = ${nm.data.home}/logs/application.log.%d{yyyy-MM-dd}.%i.log
appender.applog.strategy.type = DefaultRolloverStrategy
appender.applog.strategy.max = 9
appender.applog.strategy.fileIndex = max
appender.applog.policy.type = Policies
appender.applog.policy.1.type = TimeBasedTriggeringPolicy
appender.applog.policy.2.type = SizeBasedTriggeringPolicy
appender.applog.policy.2.size = 100MB
appender.applog.layout.type = PatternLayout
appender.applog.layout.pattern = %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5p [%t] %c - %m%n%throwable

[ ... more appenders and loggers ...]

Note the following about our example configuration:

  • Error messages are sent to STDOUT.
  • Messages from FNZ Studio (package com.nm and com.appway) are sent to STDOUT and to the log file application.log. By default, only errors and warnings are reported.
  • The log file application.log is saved in the directory <DataHome>/logs and is rotated once a day, or when the file size reaches 100 MB. The logs from the previous days have a timestamp included in their name (example: application.log.2024-10-31.1.log). If the log file is rotated because of its size, the index in the file name is incremented by 1. There is a maximum of 9 archived log files per day. Together with the current active log file, this results in a total maximum size of 10 x 100 MB = 1 GB per day.

Configuration Files

Important note: If you upgrade to FNZ Studio 2024.x or higher from FNZ Studio 2022.2 or lower, please note that the names of the Log4j configuration files have changed due to the migration from Log4j 1.2 to Log4j 2. In previous releases, the configuration files have been named `log4j.properties` and `log4j-additional.properties`. Now with Log4j 2, these configuration files have an extra "2" in the name: `log4j2.properties` and `log4j2-additional.properties`.

On startup, FNZ Studio checks if there is a file called log4j2.properties in the directory <DataHome>/conf. If the file exists, it is used to initialize Log4j. This basically REPLACES the default configuration. You can use this method if you must perform fundamental changes on how Log4j is initialized.

If you only need to add, change, or remove some configuration properties, create a file called log4j2-additional.properties. If this file exists on startup, FNZ Studio uses its content to OVERRIDE the properties loaded from the default configuration or from the log4j2.properties file above. You can use this method if you want to make a single logger level persistent:

Copy
log4j.logger.com.nm.services.WorkflowEngineServiceImpl = DEBUG

Or you can attach additional log files to FNZ Studio components:

Copy
log4j.logger.com.nm.filter.DebugFilter = DEBUG, reqlog
log4j.additivity.com.nm.filter.DebugFilter = false

appender.reqlog.type = RollingFile
appender.reqlog.name = reqlog
appender.reqlog.fileName = ${nm.data.home}/logs/reqlog.log
[...]

Setting a Log4j configuration to value TO_BE_REMOVED causes the removal of this property. As opposed to redefining a property (OVERRIDE), setting the value to TO_BE_REMOVED physically removes this property from the applied Log4j configuration. This capability is useful when simply overriding some properties invalidates other existing properties, which then need to be removed to avoid follow-up issues.

Example:

  • Default configuration is appender.lockslog.type = RollingFile;
  • To disable it, the property above needs at least to be overridden: appender.lockslog.type = Null;
  • If any RollingFile dependent properties become invalid (e.g., appender.lockslog.filePattern), errors are generated when configuring Log4j;
  • Setting the property to TO_BE_REMOVED produces a clean Log4j2-running configuration.

If you want to define a file path to a log file inside FNZ Studio's data home directory, you can use the placeholder ${nm.data.home}:

Copy
appender.myapp.fileName = ${nm.data.home}/logs/myapp.log