My FNZ Studio Version

System Maintenance

Latest Update: 16.11.2023 |
Recipe
2023

Problem

How do I add the user ID to every line in a Log4j log file?

Solution

Here's the short answer:

  1. Create a file [DataHome]/conf/log4j2-additional.properties

  2. Add the following lines to this file:

    appender.stdlog.layout.pattern = %d | %-20X{userId} | %-5p %c - %m%n%throwable
    appender.errlog.layout.pattern = %d | %-20X{userId} | %-5p %c - %m%n%throwable
    appender.dbglog.layout.pattern = %d | %-20X{userId} | %-5p %c - %m%n%throwable
    appender.libslog.layout.pattern = %d | %-20X{userId} | %-5p %c - %m%n%throwable
    
  3. Restart FNZ Studio

2 Explanation

FNZ Studio uses Log4j 2.x as logging framework (see [System Upgrade]((http://localhost:8080/screen/kb/article/system-upgrade-migrating-log4j-configuration-from-v1-to-v2-2336752193529) guide). By default, every entry in the log file contains the following information:

  • date and time
  • log level: DEBUG, INFO, WARN, ERROR or FATAL
  • logger name (component which has generated the log message)
  • log message

3 Log4j Configuration

What information is written to the log may be configured using "layout patterns". The default pattern generating log entries as described above looks like this:

%d %-5p [%t] %c - %m%n%throwable
  • %d is a placeholder for a time stamp including the current date and time.
  • %-5p will be replaced with the log level, padded on the right to have a length of at least 5 characters.
  • %t will include the name of the current Java thread.
  • %c stands for the logger name.
  • %m stands for the actual log message provided to the logger.
  • %n adds a new-line character at the end.
  • %throwable will include the Java exception message and stack trace, if an exception has been logged.

More information on layout patterns and supported placeholders can be found here:
https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout

A special feature of Log4j is the "thread context". This is a map of key/value pairs which may be used by applications to inject custom data into log entries. By default, FNZ Studio adds the following information to the thread context:

  • userId — ID of the current user
  • clientIP — IP address of the client making an HTTP request
  • httpSessionId — current HTTP session ID
  • requestId — ID of the current HTTP request (incremented by one for every request)
  • locale — Current translation language
  • versionFilter — Current version filter

To reference a thread context value in a log entry, the placeholder "%X{key}" may be used. The following pattern includes the user id immediately after the time stamp and adds white-spaces to the end of it to have a fixed-size column with:

%d | %-20X{userId} | %-5p [%t] %c - %m%n%throwable

In order to override the default layout pattern for a Log4j appender, the configuration file [DataHome]/conf/log4j2-additional.properties may be used. If this file exists, it is loaded at start-up and used to override properties defined in the default Log4j configuration.

The default Log4j configuration of FNZ Studio defines four main appenders named "stdlog", "dbglog", "errlog", and "libs.log". The first appender writes its messages to the console, the other three write their messages into the log files "debug.log", "error.log", and "libs.log". Every appender has its own layout pattern. To override the pattern for the "dbglog" appender, the following configuration may be used:

appender.dbglog.layout.pattern = %d | %-20X{userId} | %-5p %c - %m%n%throwable

IMPORTANT! FNZ Studio must be restarted in order for this configuration to have an effect.

Related Sources

© 2026 Appway AG. All Rights Reserved