JSON Log Formatter
Since version 4.1.1.164
Besides ULF and ODL logging formats available also in GlassFish 4, Payara Server Enterprise provides additional JSON format. With this format, every line in the log output is formatted as a JSON string. The log records can be then easily parsed by a JSON parser for further data processing.
To enable the JSON formatter using the Admin Console, just select JSON
from the list of Logging Formats, either for Console
or Log File
:
The following administration command will enable the JSON formatter:
asadmin> set-log-attributes com.sun.enterprise.server.logging.GFFileHandler.formatter='fish.payara.enterprise.server.logging.JSONLogFormatter'
Once the JSON formatter is enabled, the log file may look similar to this sample:
Add an underscore prefix
Since Payara Server 5.182 and 4.1.2.182
The following administration command will add the underscore prefix to field names in JSON Formatter:
asadmin> set-log-attributes fish.payara.deprecated.jsonlogformatter.underscoreprefix=true
By default, fish.payara.deprecated.jsonlogformatter.underscoreprefix
property value is false.
Once underscore prefix enabled, all JSON fields should be prefixed with underscore, similar to this sample:
Support for Additional Fields
Since Payara Server 5.22.0
The JSON Log Formatter also supports the definition of additional fields through the parameters property. This includes logging out the contents of a map.
You can set these additional fields via the LogRecord.setParameters
method, like so:
LogRecord lr = new LogRecord(Level.INFO, "some message");
lr.setParameters(new Object[]{Collections.singletonMap(correlationIdKey, correlationIdValue)});
logger.log(lr);