Working with logging categories
File log4j2.xml contains examples of how to set up logging for various logging categories. In the base configuration, Guidewire comments out most of these examples.
It is possible for both internal PolicyCenter code or custom integration code to define additional logging categories that do not show in the logging configuration file. It is also possible for third-party components, such as Apache, to provide their own logging categories. Each Guidewire application has its own unique categories as well.
In some cases, PolicyCenter does not use a particular plugin interface. In those cases, the logging category exists in file log4j2.xml, but, PolicyCenter does not use the category for logging.
Defining a logging category
You define a logging category in log4j2.xml file by using a
<Logger> element, with each
<Logger> element containing, at the minimum, the
following items:
- The name of the logging category
- The log level for that logging category.
- A pointer to the associated
<Appender>element that defines such items as the location of the log file and how to format the log message.
You use a <Logger> element to specify the name of the logging
category and its log level. Typically, you use a <RollingFile>
element to specify the output file name and location, and similar types of
information. A rolling file is one that archives the current information at a
specified time interval and then creates a new file to store the information going
forward.
You need to specify both the <Logger> element and a
<RollingFile> element in working with a logging
category.
Working with the <Logger> element
<Logger> element sets the name of the logger (the logging
category), the log level for this logging category, and it points to the actual log
file. The following example code is for the Database
category.<Logger name="Server.Database" additivity="false" level="debug">
<AppenderRef ref="DatabaseLog"/>
</Logger>- The log category is
Server.Database. - The log level is
debug. - The log file name is
DatabaseLog.
Working with the <RollingFile> element
<RollingFile> element specifies the file name and file
formatting of a log file. The following example code is for the
DatabaseLog
file.<RollingFile name="DatabaseLog" fileName="${guidewire.logDirectory}/database.log"
filePattern="${guidewire.logDirectory}/database.log%d{.yyyy-MM-dd}">
<PatternLayout pattern="${file.defaultPattern}" charset="UTF-8"/>
<TimeBasedTriggeringPolicy/>
</RollingFile>- The
nameattribute on the<RollingFile>element (DatabaseLog) matches the ref attribute on the associated<Logger>element. - The
filenameattribute specifies the file path and file name of the database log and uses a variable for the file path. - The
filePatternattribute specifies the pattern to use in creating the log file name and again uses a variable for the file path. - The
<PatternLayout>element specifies how to format the text in the log file, using a variable to point to a default pattern.
