Severity Level | Severity Name | Category |
60 | Fatal | Error |
50 | Critical | Error |
40 | Minor | Error |
30 | Warning | Warning |
20 | Harmless | Warning |
10 | Information | Information |
0 | Unknown | Information |
The pattern layout class provides a flexible way of creating custom layouts using a printf like conversion pattern. The pattern string consists of plain text interspersed with escape sequences that will be substituted with event information. Each escape sequence consists of the character '@' followed by a predefined character that represents the information that will be substituted. The following table lists the escape sequences supported by the pattern layout.
Escape Sequence | Result |
@@ | Insert the literal character '@' |
@c | Insert the name of the logger that raised the event. |
@d | Insert the event date |
@t | Insert the event time |
@m | Insert the event message |
@r | Insert a date and time relative to the start of execution |
@s | Insert the event severity |
@n | Insert new line |
Any other text not preceded by an '@' character is inserted as is. If any other character follows an '@' sign then an error will be raised. You can further modify the output of each escape sequence by adding format modifiers between the '@' sign and the specifier character. The next table shows the types of format modifiers you can use.
Escape Sequence |
Left Justify
|
Minimum Width
|
Maximum Width
|
Description |
@20c |
False
|
20
|
none
|
Set the minimum length to 20 characters and right justify. Left pad with spaces if the logger name is less than 20 characters in length. |
@-20c |
True
|
20
|
none
|
Set the minimum length to 20 characters and left justify. Right pad with spaces if the logger name is less than 20 characters in length. |
@.30c |
N/A
|
none
|
30
|
Set the maximum length to 30 characters. Truncates from the beginning if the logger name is longer than 30 characters. |
@20.30c |
False
|
20
|
30
|
Set the minimum length to 20 and the maximum length to 30 and right justify. Left pad if the logger name is shorter than 20 characters or truncate if it is longer than 30 characters. |
@-20.30c |
True
|
20
|
30
|
Set the minimum length to 20 and the maximum length to 30 and left justify. Right pad if the logger name is short than 20 characters or truncate if it is longer than 30 characters. |
The following convertion pattern:
@d @t [@12s] @c - @m%N
Will result in log events formatted with a date, space character, left square bracket, priority (left justified in a 6 character string), right square bracket, space character, the logger name, another space, the message, and finally, a newline character (which in Eiffel is converted to an appropriate %R%N pair if required by the operating system). Therefore, a log event sent to a logger named audit, with the severity INFORMATION and with the message "xyz successfully logged in", would result in the formatted string:
2006/10/16 6:30:00 [INFORMATION ] audit - xyz successfully logged in
<?xml version="1.0"?> |
local |
command_string := xml_config_file | logger_severity xml_config_file := "file:"+a_path_to_a_xml_file logger_severity := "logger:"+logger_name+":set_severity:"+severity_name severity_name := "FATAL" | "CRITICAL" | "MINOR" | "WARNING" | "HARMLESS" | "INFORMATION" |
local h: ELOG_HIERARCHY logger, logger2: ELOG_LOGGER a1, a2, a3: ELOG_APPENDER do create h.make (Warning_severity) -- this creates a logger hierarchy, containing only the root logger logger := h.logger ("test") -- now we have the root logger and a logger called 'test' -- inheriting from it. The logger test inherits the severity -- level 'Warning_severity' because its severity is Void. logger2 := h.logger ("a.b.c") -- this implicitly creates the loggers 'a', 'a.b' (inheriting -- from 'a') and 'a.b.c' (inheriting from 'a.b') h.logger ("a.b").set_severity (Critical_severity) -- The severity of 'a.b' has been set to 'Critical_severity'. -- The logger 'a.b.c' has inherited this severity. -- Note: we still cannot log anything, because no appenders -- are attached by default. create {ELOG_STDOUT_APPENDER} a1.make ("stdout appender 1") h.logger ("a.b").add_appender (a1) -- Note: if a logger is used multiple times, it is better to -- copy the reference of the logger, than to fetch it every -- time by its name, because retreiving the actual instance of -- the logger takes some time. logger2.log_warning (create {ELOG_SIMPLE_EVENT}.make ( "This will not be printed because the severity sevel is "+ "lower than the level of the appender")) logger2.log_critical (create {ELOG_SIMPLE_EVENT}.make ( "This will be printed because the severity sevel is "+ "greater or equal to the level of the appender")) a1.set_synchronous_wait -- this will set the appender to synchronous and wait until -- the consumer thread has consumed all events. logger2.log_fatal (create {ELOG_SIMPLE_EVENT}.make ( "This log is beeing handled synchronously. ")) end |
logger.set_severity (Fatal_severity) logger.log_warning (create {ELOG_SIMPLE_EVENT}.make ("some log event")) |
logger.set_severity (Fatal_severity) if logger.is_enabled_for (Warning_severity) then logger.log_warning (create {ELOG_SIMPLE_EVENT}.make ("some log event")) end |