log4j APL Logging Configurations

log4j APL Logging Configurations

The system includes a log4j extension that enables generation of customized logs from agents configured with APL. This section describes how to configure these logs to meet deployment specific requirements.

Configuration Files

There is a configuration file called apl-log4j.properties containing default settings located in the $MZ_HOME/etc/logging directory that is used to specify the path of log files, log filtering rules, log level and formatting. If you want to use different settings for different Execution Contexts, this file can be copied and renamed to <ec-name>-apl-log4j.properties where you can configure different settings for the specified EC.

To provide some examples and templates, there are a number of pre-existing files with the name apl-log4j-<log level name>.properties, for example apl-log4j-trace.properties, which you can use to either copy properties from, or make a copy of the whole file and rename it to <ec-name>-apl-log4j.properties. 

Example - Configuration filenames

Default configuration file:

$MZ_HOME/etc/logging/apl-log4j.properties

EC specific configuration file for ec1:

$MZ_HOME/etc/logging/ec1-apl-log4j.properties

Copying the default configuration file into an EC specific configuration file:

$cp apl-log4j.properties ec1-apl-log4j.properties

Copying a template configuration file into an EC specific configuration file:
$cp apl-log4j-trace.properties ec1-apl-log4j.properties

The following template configuration files are included by default:

  • apl-log4j-off.properties

  • apl-log4j-fatal.properties

  • apl-log4j-error.properties

  • apl-log4j-warn.properties

  • apl-log4j-info.properties

  • apl-log4j-debug.properties

  • apl-log4j-trace.properties

  • apl-log4j-all.properties

The files listed above have a different log level setting but are otherwise identical.

Whenever the APL function log.* is called in the Analysis agent, this function invokes logging with log4j. After the workflow is done executing with a specific EC, a new EC specific configuration file <ec-name>-apl-log4j.properties will be created. This new EC specific configuration file is created by default with the same configurations saved in the file apl-log4j.properties. For instance, if the EC name is ec1 then ec1-apl-log4j.propertiesis created in $MZ_HOME/etc/logging and will have identical settings as apl-log4j.properties.

MZSH does not support dedicated commands to make changes to the log level. Changes on the log level and other properties in the configuration file must be made manually. Whatever changes made to the configuration file takes effect at the next workflow run without the need to restart the EC.

In a multi-host installation, the EC specific configuration file is always created on the host where EC is located. Therefore, log4j always read the EC specific configuration according to the EC location. For instance, workflow run by ec1 located on host my-host-name. The log4j always read the EC specific configuration file ec1-apl-log4j.properties located at path $MZ_HOME/etc/logging on host my-host-name.

The content of the files defines the logging.

Example - Configuration file contents

log4j.logger.aplLogger=ALL, a
log4j.appender.a=com.digitalroute.apl.log.DRRollingFileAppender
log4j.appender.a.file=${mz.home}/log/{pico}_{workflow}.log
log4j.appender.a.layout=com.digitalroute.apl.log.JsonLayout
log4j.appender.a.layout.MdcFieldsToLog=pico, workflow, agent, tag

The first line in the example above sets the log level and declares an "appender" named 'a'. The available log levels are listed below in order of severity, from highest to lowest:

  • OFF

  • FATAL

  • ERROR

  • WARN

  • INFO

  • DEBUG

  • TRACE

  • ALL

Messages of the same or higher severity than the selected level are logged. For instance, if the configured log level is WARN, messages with the severity ERROR and FATAL will be logged as well. The other settings above mean that messages are logged in files that are started, stopped and stored in JSON formatted files in the $MZ_HOME/log directory in regular intervals. When an active log file has reached its maximum size, it is backed up and stored with a number suffix. A new active log file is then created. The default maximum size is 10 MB, and the default number of backup files is one (1).

Appenders

The APL log extension provides the appender DRRollingMultiFileAppender. It writes one log file per distinct value of the log4j.appender.<appender name>.file property after the placeholders {pico}, {workflow} and {agent} have been substituted at runtime. For example, a path containing {workflow} produces one file per workflow instance, while a fixed path with no placeholders produces a single file shared by all workflows routed to that appender.

Which workflows are written to which appender is controlled by the log4j.logger.aplLogger.<configuration name> property.

Note!

DRRollingFileAppender is deprecated and retained only for backward compatibility with existing configuration files. It is an alias for DRRollingMultiFileAppender and behaves identically. It no longer writes to a single designated file. Existing configurations that reference it continue to work unchanged:

log4j.appender.a=com.digitalroute.apl.log.DRRollingFileAppender is equivalent to log4j.appender.a=com.digitalroute.apl.log.DRRollingMultiFileAppender

Use DRRollingMultiFileAppender in new configurations.

Examples - Appender Configurations

The number of log files an appender writes is determined by the placeholders in its file property. {pico}, {workflow} and {agent} are replaced at runtime, and one rolling log file is created for each distinct resolved path.

# DefaultFolder log4j.appender.DefaultFolder=com.digitalroute.apl.log.DRRollingMultiFileAppender log4j.appender.DefaultFolder.file=${mz.home}/log/log4j/default_folder.log log4j.appender.DefaultFolder.layout=org.apache.log4j.PatternLayout log4j.appender.DefaultFolder.layout.ConversionPattern=[%d{dd MMM yyyy HH:mm:ss,SSS}];[%-5p];[pico=%X{pico}];[%t];[tag=%X{tag}];[%c]:%m%n log4j.appender.DefaultFolder.MaxFileSize=10MB log4j.appender.DefaultFolder.MaxBackupIndex=20 log4j.logger.aplLogger.Default=TRACE, DefaultFolder

The appender named DefaultFolder receives log events from all workflows under the Default folder. Because the file path contains no placeholders, all of them are written to the single file default_folder.log.

# PerWorkflow log4j.appender.PerWorkflow=com.digitalroute.apl.log.DRRollingMultiFileAppender log4j.appender.PerWorkflow.file=${mz.home}/log/log4j/{workflow}.log log4j.appender.PerWorkflow.layout=org.apache.log4j.PatternLayout log4j.appender.PerWorkflow.layout.ConversionPattern=[%d{dd MMM yyyy HH:mm:ss,SSS}];[%-5p];[pico=%X{pico}];[%t];[tag=%X{tag}];[%c]:%m%n log4j.appender.PerWorkflow.MaxFileSize=10MB log4j.appender.PerWorkflow.MaxBackupIndex=20 log4j.logger.aplLogger.RT_Folder.RT_TEST_WF=TRACE, PerWorkflow

The appender named PerWorkflow receives log events from all instances of the RT_Folder.RT_TEST_WF workflow. Because the file path contains {workflow}, each workflow instance is written to its own file, named after the instance, for example RT_Folder.RT_TEST_WF.workflow_1.log and RT_Folder.RT_TEST_WF.workflow_2.log.

# PerAgent log4j.appender.PerAgent=com.digitalroute.apl.log.DRRollingMultiFileAppender log4j.appender.PerAgent.file=${mz.home}/log/log4j/{pico}_{workflow}_{agent}.log log4j.appender.PerAgent.layout=com.digitalroute.apl.log.JsonLayout log4j.appender.PerAgent.layout.MdcFieldsToLog=pico, workflow, agent, tag log4j.appender.PerAgent.MaxFileSize=10MB log4j.appender.PerAgent.MaxBackupIndex=20 log4j.logger.aplLogger.RT_Folder.RT_TEST_WF=TRACE, PerAgent

The appender named PerAgent writes one file per combination of Execution Context, workflow instance and agent, for example ec1_RT_Folder.RT_TEST_WF.workflow_1_Analysis_1.log.

 

You can change the maximum file size and the number of backup files by adding the following lines:
log4j.appender.a.MaxFileSize=100MB
log4j.appender.a.MaxBackupIndex=10

You can add a filtering rule by adding the line log4j.logger.<configuration name>=<log level>. This is useful when you want to set different log levels for specific folders or configurations.

Example. Sets the general log level to ERROR and to DEBUG for the agent named agent_1

log4j.rootLogger=ERROR, a 
log4j.appender.a=com.digitalroute.apl.log.DRRollingMultiFileAppender
log4j.appender.a.file=${mz.home}/log/{pico}_{workflow}.log
log4j.appender.a.layout=com.digitalroute.apl.log.JsonLayout
log4j.logger.aplLogger.Default.debug.workflow_1.agent_1=DEBUG

If you want to apply the filtering rule to all APL configurations in the default folder, change the last line in the previous example to log4j.logger.Default=DEBUG.

For more information about available settings, see the log4j documentation at https://logging.apache.org/log4j/1.2/manual.html.

APL Commands

The following functions are used to trigger logging within any of the function blocks in APL:

  • void log.fatal(any, any)

  • void log.error(any, any)

  • void log.warn(any, any)

  • void log.info(any, any)

  • void log.debug(any, any)

  • void log.trace(any, any)

For more information about these functions, see Log and Notification Functions.

Log Output

The output log files are stored in the directory specified in the active logging configuration.

Example - Log file in JSON format

{"timestamp":"2015-12-20:22:44:10 UTC","level":"DEBUG","thread":"Default.logtestwf.workflow_1: TCP_IP_1_1","category":"Default.logtestwf.workflow_1.Analysis_1","message":"In consume","pico":"EC1","workflow":"Default.logtestwf.workflow_1","agent":"Analysis_1"}


The fields in the log output are described below.

Field

Description

Field

Description

timestamp

The time when the message was logged. The UTC timezone and international standard date and time notation is used by default. 
You can specify the date format by adding the following line in the configuration file:

log4j.appender.a.layout.DateFormat=<Java SimpleDateFormat pattern>

For information about how to use SimpleDateFormat patterns, see:
https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

level

The log level i e FATAL, ERROR, WARN, INFO, DEBUG, or TRACE.

thread

The name of the workflow thread.

category

The logged configuration. This field contains the category class of the appender that is defined in the configuration file.

message

The log message is specified in the APL command.

pico

The name of the Execution Context.

Warning!

The ECs must be restarted if you manually delete or rename active log files or backup log files.

Hint!

  If the log files are not generated as expected, review the EC logs. Your configuration files may contain errors.