Formatting Log Messages
The logged output of a logger can be customized to any format, such as an XML or a human readable format.
Typically each logging Handler
will have a Formatter
associated with it. The Formatter
takes a LogRecord
and converts it to a string. The default Formatter
assigned to the Handlers
declared in the logging configuration file is com.gigaspaces.logger.
GSSimpleFormatter
. This formatter is based on the java.util.logging.
SimpleFormatter
class, which prints a brief summary of the LogRecord
in a human readable format.
The format
Property
The LogRecord
passed to the Formatter
is converted to a string, as specified by the format
property in the logging configuration file.
Placeholders
The format is simply a string, which can contain any character including line-break characters. GigaSpaces provides several placeholders that can be added to the message.
0 - Date object
1 - Class name
2 - Method name
3 - Log Level
4 - Logger name
5 - Message
6 - Context (processing unit This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity., GSC Grid Service Container.
This provides an isolated runtime for one (or more) processing unit (PU) instance and exposes its state to the GSM., etc)
7 - Thread name
Additional placeholders are defined in the xap_logging.properties
file in the ...config/log
folder.
Default Format
By default, the logging configuration file comes with the following as the default format:
com.gigaspaces.logger.GSSimpleFormatter.format = {0,date,yyyy-MM-dd HH:mm:ss,SSS} {6} {3} [{4}] - {5}
Which translates to: *Date and time printed down to the millisecond, context (if available), the log level of the message, the logger name and the message.
Customized Format
If you wish to customize the format, change the default setting the in the logging configuration file (<GigaSpaces>/config/log/xap_logging.properties
).
For example,
com.gigaspaces.logger.GSSimpleFormatter.format={0,date} {1}.{2}(..) {3} - {5}
Which translates to: Date in it's simplest form, Class name and method, the log level of the message and the message
Jul 14, 2009 com.gigaspaces.Class.method(..) INFO - Sample message
For more details on how to customize a message, refer to java.text.MessageFormat and java.text.SimpleDateFormat.