Contents
Log4j2 Configuration with the Application Template Application Block
Platform SDK Application Template Application Block contains Log4j2 plugin component for logging configuration.
Its goal is to allow application to configure logging in accordance to the Common Genesys Logging Options with Log4j2 library.
Enabling and configuring PSDK log4j2 logging
Using AppTemplate Configuration Manager
GFApplicationConfigurationManager, once initialized, automatically applies and listen for updates in the application logging configuration.
public class MyApplication {
protected static final LmsEventLogger LOG = LmsLoggerFactory.getLogger(MyApplication.class);
...
GFApplicationConfigurationManager appManager =
GFApplicationConfigurationManager.newBuilder()
.withCSEndpoint(new Endpoint("CS-primary", csHost1, csPort1))
.withCSEndpoint(new Endpoint("CS-backup", csHost2, csPort2))
.withClientId(clientType, clientName)
.withUserId(csUsername, csPassword)
.build();
appManager.register(new GFAppCfgOptionsEventListener() {
public void handle(final GFAppCfgEvent event) {
Log.getLogger(getClass()).info("The application configuration options received: " + event);
// Init or update own application options from 'event.getAppConfig()'
}});
appManager.init();
// LmsEventLogger method usage:
LOG.log(CommonLmsEnum.GCTI_APP_INIT_COMPLETED);
// Common ILogger method usage:
LOG.info("Some Log4j2 info message");
...
For more details see Additional Logging Features.
Using AppTemplate API calls
If GApplicationConfigurationManager is not used, its still possible to configure logging in the same way by using AppTemplate API calls.
In package "com.genesyslab.platform.apptemplate.log4j2" AppTemplate provides classes named PsdkLog4j2Configuration and Log4j2Configurator.
Main cases are following:
- Create PsdkLog4j2Configuration with its factory method "parse(KeyValueCollection)" and set it with the configurator (Log4j2Configurator.setConfig()). It uses optional config profile and given application Options "log" sections, and configures. Drawbacks: no "log-extended" Options section is taken into account, no Message Server appender from the application connections.
- Obtain IGApplicationConfiguration and apply it with the configurator (Log4j2Configurator.applyLoggingConfig()). The application configuration may be explicitely filled using GApplicationConfiguration, or automatically initialized from ConfService using COMGApplicationConfiguration. This way includes initialization of "log-extended" Options sections and may add Message Server appender if its properly configured in the application configuration. Note: this configuration appliance method also switches PSDK loggers to send their logs to Log4j2 (if it was not enabled earlier).
More details on enabling of PSDK logging may be found in Setting up Logging in Platform SDK.
Switch PSDK logging to log4j2 with system properties
The following properties are supported:
- "-Dcom.genesyslab.platform.commons.log.loggerFactory=log4j2" to switch PSDK commons logging implementation to send logs to log4j2.
- "-Dcom.genesyslab.platform.apptemplate.lmslogger.factory=log4j2" to switch AppTemplate LmsEventLogger's to send logs and LMS events to log4j2.
AppTemplate Logging configuration profile
AppTemplate logging configuration profile is a usual Log4j2 xml configuration file. And it may be used as "startup configuration" before application is initialized and read its configuration from Configuration Server.
For details on Log4j2 configuration details see: http://logging.apache.org/log4j/2.x/manual/configuration.html.
To use "log4j2.xml" as the config profile, it should be referred with application CME Option:
[log]
"log4j2-config-profile"="log4j2.xml"
Example of startup logging configuration with logs formatted in the common Genesys LMS style:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.genesyslab.platform.apptemplate.log4j2plugin">
<Appenders>
<GLogFile name="PSDKAppTpl-LogFile" fileName="startup.log">
<GLmsLayout timeFormat="locale" messageFormat="full"/>
<GLogRolloverStrategy expConfig="8 days"/>
</GLogFile>
<GLogFile name="PSDK" fileName="psdk.log">
<GLmsLayout timeFormat="locale" messageFormat="full"/>
<GLogRolloverStrategy expConfig="8 days"/>
</GLogFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="PSDKAppTpl-LogFile"/>
</Root>
<Logger name="com.genesyslab.platform" level="debug">
<AppenderRef ref="PSDK"/>
</Logger>
</Loggers>
</Configuration>
Logging profile feature: "startup" appenders
Appenders, which have "PSDKAppTpl-" prefix in their names are treated as "startup" appenders.
Those ones are actual when the config profile is used as a usual log4j2 configuration file at the application startup time. But, when application has started, loaded its application configuration options, and called AppTemplate logging configuration (referring this profile), the "startup" appenders are excluded from the new configuration.
Logging profile feature: separate subsystems logs
Specifics of the Genesys Logging Configuration Options is that log files may be generated and filtered by evel level, but not by logger or "source" name. I.e. generated by the "log" appenders are added to the "root" logger of logging configuration.
Logging configuration profile allows creation of dedicated appenders and custom loggers declaration for collecting of specific subsystem(s) logs separately from main application logs.
Example of such configuration is in the config profile sample above - appender named "PSDK", and logger named "com.genesyslab.platform". This file name is "hardcoded" in the config profile and can't be changed from application CME Options. But its still possible to change following parameters of the logger with "logger-<id>" option in "log-extended" section: "level" and "additivity" (see details bellow). By this way, its possible to change messages level of the PSDK log file, and to add or exclude PSDK messages from main application log files.
Useful Platform SDK loggers for optional configuration
PSDK root logger
Platform SDK loggers are named under PSDK base package - "com.genesyslab.platform". Usage of this logger name allows applications to separately configure, filter and record PSDK internal logs.
Protocol messages tracing loggers
Usually, PSDK generates debug logs reflecting Protocols communications messages in truncated form together with other debug messages.
Sometimes applications may need to have separated recordings of protocols communications messages dumps.
For this purpose PSDK contains dedicated loggers:
- "com.genesyslab.platformmessage.request",
- "com.genesyslab.platformmessage.receive",
- and their common name - "com.genesyslab.platformmessage".
By default, these loggers are disabled. Its possible to enable them with jvm system property "-Dcom.genesyslab.platform.trace-messages=true".
These values enable tracing for Config Server and Stat Server protocols only. "Branched" options names are constructed by insertion of a string representation of specific ProtocolDecription value (see DuplexChannel.getProtocolDescription().toString()).
It's possible to provide several different declarations for different protocols at a same time. It's also possible to enable tracing for the common property ("enable by default"), and disable for some specific protocols.
ADDP logger
There is a dedicated specially named logger for ADDP traces - "com.genesyslab.platform.ADDP".
It's for possible adjustment of ADDP traces logging filtering.
Application CME Logging Options
The AppTemplate logging configuration is based on AppTemplate Application Configuration structure as a snapshot representation of a COM AB CfgApplication structure.
Following values are taken into account: "log" and "log-extended" sections of the applications' "Options", and connected Message Server CME application.
Options section "log"
Most of this section options are inherited from the Genesys Common Log Options descriptions, as listed in the Framework 8.5 Configuration Options Reference Manual.
verbose
Specifies if log output is created, and if so, the minimum level of log events generated. Log event levels, starting with the highest priority level, are Standard, Interaction, Trace, and Debug. |
Default Value: all |
Valid Values:
|
Changes Take Effect: Immediately |
Additional Information: Note: For definitions of the Standard, Interaction, Trace, and Debug log levels, refer to the Framework Management Layer User’s Guide or Framework Genesys Administrator Help.
To configure log outputs, set log level options ("all", "alarm", "standard", "interaction", "trace", and/or "debug") to the desired types of log output ("stdout", "stderr", "network", "memory", and/or [filename], for log file output). You can use:
You must separate the log output types by a comma when you are configuring more than one output for the same log level. |
all
Specifies the outputs to which an application sends all log events. The log output types must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: all = stdout, logfile
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
alarm
Specifies the outputs to which an application sends the log events of the Alarm level. The log output types must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: alarm = stderr, network
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
standard
Specifies the outputs to which an application sends the log events of the Standard level. The log output types must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: standard = stdout, logfile
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
interaction
Specifies the outputs to which an application sends the log events of the Interaction level and higher (that is, log events of the Standard and Interaction levels). The log outputs must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: interaction = stdout, logfile
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
trace
Specifies the outputs to which an application sends the log events of the Trace level and higher (that is, log events of the Standard, Interaction, and Trace levels). The log outputs must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: trace = stdout, logfile
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
debug
Specifies the outputs to which an application sends the log events of the Debug level and higher (that is, log events of the Standard, Interaction, Trace, and Debug levels). The log output types must be separated by a comma when more than one output is configured. |
Default Value: No default value. |
Valid Values: Log output types:
|
Changes Take Effect: Immediately |
Additional Information: For example: debug = stdout, logfile
Note1: The log output options are activated according to the setting of the Verbose configuration option. Note2: To ease the troubleshooting process, consider using unique names for log files that different applications generate. Note3: Debug-level log events are never sent to Message Server or stored in the Log Database. Warning! Directing log output to the console (by using "stdout", "stderr" settings) can affect application performance. Avoid using these log output settings in a production environment. |
segment
Specifies whether there is a segmentation limit for a log file. If there is, sets the mode of measurement, along with the maximum size. If the current log segment exceeds the size set by this option, the file is closed and a new one is created. This option is ignored if log output is not configured to be sent to a log file. |
Default Value: 100 MB |
Valid Values:
|
Changes Take Effect: Immediately
|
expire
Determines whether log files expire. If they do, sets the measurement for determining when they expire, along with the maximum number of files (segments) or days before the files are removed. This option is ignored if log output is not configured to be sent to a log file. |
Default Value: 10 |
Valid Values:
|
Changes Take Effect: Immediately |
Additional Information: Note: If an option’s value is set incorrectly (out of the range of valid values), it will be automatically reset to 10. |
compress-method
Platform SDK AppTemplate AB specific property to specify method that will be used for archiving log files.
The log option name is case insensitive, and can be "CompressMethod", "compress-method", or "compress_method". |
Default Value: none |
Valid Values:
|
Changes Take Effect: Immediately |
Introduced in release: 9.0.003.01 |
time-convert
Specifies the system in which an application calculates the log record time when generating a log file. The time is converted from the time in seconds since "00:00:00 UTC, January 1, 1970".
The log option name is case insensitive, and can be: "TimeConvert", "time-convert", or "time_convert". |
Default Value: local |
Valid Values:
|
Changes Take Effect: Immediately
|
time-format
Specifies how to represent, in a log file, the time when an application generates log records. A log record’s time field in the ISO 8601 format looks like this: "2001-07-24T04:58:10.123".
The log option name is case insensitive, and can be: "TimeFormat", "time-format", or "time_format". |
Default Value: time |
Valid Values:
|
Changes Take Effect: Immediately
|
message-format
Specifies the format of log record headers that an application uses when writing logs in the log file. Using compressed log record headers improves application performance and reduces the log file's size. With the value set to short:
The log option name is case insensitive, and can be: "MessageFormat", "message-format", or "message_format". |
Default Value: medium |
Valid Values:
|
Changes Take Effect: Immediately |
Additional Information: A log record in the full format looks like this:
2002-05-07T18:11:38.196 Standard localhost cfg_dbserver GCTI-00-05060 Application started A log record in the short format looks like this: 2002-05-07T18:15:33.952 Std 05060 Application started Note: Whether the full, short, or any other format is used, time is printed in the format specified by the "time-format" option. |
use-native-levels
Platform SDK AppTemplate AB specific option.
It enables support of native log levels (like "Error", "Warn", etc) to be used for non-LMS messages in common LMS events formats instead of LMS levels like "Standard", "Interaction", etc. The log option name is case insensitive, and can be: "UseNativeLevels", "use-native-levels", or "use_native_levels". Note: This option is experimental and its value procession may get changed.
|
Introduced in release: 9.0.002.09 |
message-header-delimiter
Platform SDK AppTemplate AB specific property as a parameter for "shortdsv" message format ("message-format").
The log option name is case insensitive, and can be: "MessageHeaderDelimiter", "message-header-delimiter", or "message_header_delimiter". |
Default Value: |
|
custom-message-format
Platform SDK AppTemplate AB specific option.
Value of this option is used as a log message pattern if "message-format" option value is equal to "custom". In comparison with "output-pattern", this option provides predefined messages prefix containing timestamp (by "time-format"/"time-convert"), and the LMS-style log level. The log option name is case insensitive, and can be: "CustomMessageFormat", "custom-message-format", or "custom_message_format". Note: This option is experimental and its value procession may get changed.
|
Introduced in release: 9.0.002.01 |
output-pattern
Platform SDK AppTemplate AB specific option.
Value of this option is used as a log message pattern if "message-format" option value is equal to "custom". In comparison with "custom-message-format", this option does not provide predefined messages prefix like a timestamp with log level. The log option name is case insensitive, and can be: "OutputPattern", "output-pattern", or "output_pattern".
|
Introduced in release: 9.0.002.05 |
file-encoding
Platform SDK AppTemplate AB specific property for configuration of the log files encoding.
The log option name is case insensitive, and can be: "FileEncoding", "file-encoding", or "file_encoding". |
Default Value: UTF-8
|
file-header-provider
Platform SDK AppTemplate AB specific property for customization of the log files header content.
The log option name is case insensitive, and can be: "FileHeaderProvider", "file-header-provider", or "file_header_provider".
|
Additional Information: If this option is not specified, then the provider is taken with SPI declaration for the com.genesyslab.platform.apptemplate.log4j2plugin.FileHeaderProvider interface. |
enable-thread
Specifies whether to enable or disable the logging thread. If set to true (the logging thread is enabled), the logs are stored in an internal queue to be written to the specified output by a dedicated logging thread. This setting also enables the log throttling feature, which allows the verbose level to be dynamically reduced when a logging performance issue is detected.
The log option name is case insensitive, and can be: "EnableThread", "enable-thread", or "enable_thread". |
Default Value: false |
Valid Values: true, false |
Additional Information: Refer to the Framework 8.5 Management Framework User’s Guide for more information about the log throttling feature.
If this option is set to false (the logging thread is disabled), each log is written directly to the outputs by the thread that initiated the log request. This setting also disables the log throttling feature. Note: Platform SDK AppTemplate AB does not support the log throttling feature. |
enable-location-for-thread
Platform SDK AppTemplate AB specific option to enable the call location information passing to the Log4j2 logging thread, which was enabled with option "enable-thread".
The log option name is case insensitive, and can be: "EnableLocationForThread", "enable-location-for-thread", or "enable_location_for_thread".
|
Additional Information: If one of the layouts is configured with a location-related attribute like HTML locationInfo, or one of the patterns %C or $class, %F or %file, %l or %location, %L or %line, %M or %method, Log4j will take a snapshot of the stack, and walk the stack trace to find the location information.
This is an expensive operation: 1.3 - 5 times slower for synchronous loggers. Synchronous loggers wait as long as possible before they take this stack snapshot. If no location is required, the snapshot will never be taken. However, asynchronous loggers need to make this decision before passing the log message to another thread; the location information will be lost after that point. The performance impact of taking a stack trace snapshot is even higher for asynchronous loggers: logging with location is 4 - 20 times slower than without location. For this reason, asynchronous loggers do not include location information by default. |
log4j2-config-profile
Platform SDK AppTemplate AB specific option.
It defines a base structure and may contain some predefined startup or permanent appenders, and initial custom loggers configurations. The log option name is case insensitive, and can be: "Log4j2ConfigProfile", "log4j2-config-profile", or "log4j2_config_profile".
|
default-logdir
Platform SDK AppTemplate AB specific option.
Default root directory for the log files. If specified, it is applied to file names defined in options like "standard", "interaction", "debug", etc. It's used if log file name is not absolute path, and is not started from "./", or "../". Note: This option value may be overridden with jvm system property "default-logdir". The log option name is case insensitive, and can be: "DefaultLogdir", "default-logdir", or "default_logdir".
|
Introduced in release: 9.0.005.00 |
msgsrv-intMsgsLevel
Platform SDK AppTemplate AB specific property to set log messages filter on Message Server Appender for Platform SDK internal events.
This value should not be lower than INFO level to not cause unlimited recursion/avalanche. The log option name is case insensitive, and can be: "msgsrv-intMsgsLevel", "msgsrv_intMsgsLevel". |
Default Value: info |
Valid Values: info, warn, error, fatal, off |
Changes Take Effect: Immediately |
Introduced in release: 9.0.005.02 |
message-file
Specifies the file name for application-specific log events. The name must be valid for the operating system on which the application is running. The option value can also contain the absolute path to the application-specific *.lms file. Otherwise, an application looks for the file in its working directory.
The log option name is case insensitive, and can be: "MessageFile", "message-file", or "message_file". |
Default Value: As specified by a particular application |
Valid Values: Any valid message file ("<filename>.lms") |
Changes Take Effect: Immediately, if an application cannot find its "*.lms" file at startup |
Additional Information: For example:
message-file = my-app.lms Warning! An application that does not find its *.lms file at startup cannot generate application-specific log events and send them to Message Server. |
event-log-host
Platform SDK AppTemplate AB specific property to let user applications be able to override the applications' host name in log files and message server events.
It is used by the AppTemplate Log4j2 logging configuration functions in PsdkLog4j2Configuration and Log4j2Configurator. The log option name (case insensitive): "EventLogHost", "event-log-host", or "event_log_host".
|
Changes Take Effect: Immediately |
Additional Information: For example:
event-log-host = node-1-virtual-host |
Options section "log-extended"
Some of this section options are inherited from the Genesys Common Log Options descriptions, as listed in the Framework 8.5 Configuration Options Reference Manual.
level-reassign-disable
When this option is set to true, the original (default) log level of all log events in the [log-extended] section are restored. This option is useful when you want to use the default levels, but not delete the customization statements. |
Default Value: false |
Valid Values: true, false |
Changes Take Effect: Immediately
|
level-reassign-<eventID>
Specifies a log level for log event <eventID> that is different than its default level, or disables log event <eventID> completely. If no value is specified, the log event retains its default level. |
Default Value: Default value of log event <eventID> |
Changes Take Effect: Immediately |
Additional Information: This option is useful when you want to customize the log level for selected log events.
These options can be deactivated with the level-reassign-disable option. See Genesys Common Log Options descriptions section of Framework 8.5 Configuration Options Reference Manual for more details on this option. Example: this example shows customized log level settings, subject to the following log configuration: [log]
verbose = interaction
all = stderr
interaction = log_file
standard = network Before the log levels of the log are changed:
Extended log configuration section: [log-extended]
level-reassign-1020 = none
level-reassign-2020 = interaction
level-reassign-3020 = interaction
level-reassign-4020 = standard After the log levels are changed:
|
logger-<id>
Platform SDK specific extended logging configuration option for applying of custom properties on loggers configuration.
|
Changes Take Effect: Immediately |
Additional Information: The "log-extended" section of CME Application Options may contain multiple declarations of loggers customization records.
For example: [log-extended]
logger-ID1 = "logger1.name: level=debug, additivity=false"
logger-ID2 = "logger2.name: level=error" "ID1" and "ID2" are just unique identifiers of the logger declarations in the options section. "logger1.name" and "logger2.name" are loggers names in a common log4j sense of loggers naming convention. These values will be applied to the internally generated log4j2 configuration in the following way (the declarations will be created, or adjusted, if already exist): <Loggers>
<Logger name="logger1.name" level="debug" additivity="false" />
<Logger name="logger2.name" level="error" />
</Loggers> It's included in GAppLogExtOptions, which may contain list of such descriptions, and is a part of GAppLoggingOptions. The custom logger declaration supports following (optional) properties:
|