Logging Configuration

Logging Configuration

Appenders

The ability to selectively enable of dissable logging request based on their loggers is only part of the picture. This system allows logging requests to print to multiple destinations. An output destination is called an appender.
Current system defines appenders for Console, files and Database, but can be easily extended to remote socket server, NT event loggers, syslog daemons or any other system.

More than one appender can be attached to one logger. Each enabled logging request for a given logger will be forwarded to all the appenders in that logger

Configuration

System will read all config elements with prefix "Logger." and "Appender." and configure the logging system. If "root" can not be properly configured the core will remove all loggers and appenders and create a default set:

  • Logger "root" with log level Error

  • Logger "server" with log level Info

  • Appender "Console" to log to console


Appender config line follows the format:

Type,LogLevel,Flags,optional1,optional2

Its a list of elements separated by comma where each element has its own meaning

Type: Type of the appender

1 - (Console)
2 - (File)
3 - (DB)

LogLevel: Log level

0 - (Disabled)
1 - (Trace)
2 - (Debug)
3 - (Info)
4 - (Warn)
5 - (Error)
6 - (Fatal)

Flags: Define some extra modifications to do to logging message

1 - Prefix Timestamp to the text
2 - Prefix Log Level to the text
4 - Prefix Log Filter type to the text
8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS (Only used with Type = 2)
16 - Make a backup of existing file before overwrite (Only used with Mode = w)

Depending on the type, elements optional1 and optional2 will take different

Colors (read as optional1 if Type = Console)

Format: "fatal error warn info debug trace"
0 - BLACK
1 - RED
2 - GREEN
3 - BROWN
4 - BLUE
5 - MAGENTA
6 - CYAN
7 - GREY
8 - YELLOW
9 - LRED
10 - LGREEN
11 - LBLUE
12 - LMAGENTA
13 - LCYAN
14 - WHITE
Example: "13 11 9 5 3 1"

File: Name of the file (read as optional1 if Type = File)
Allows to use one "%u" to create dynamic files

Mode: Mode to open the file (read as optional2 if Type = File)

a - (Append)
w - (Overwrite)

 

Example:

Appender.Console1=1,2,6

Creates new appender to log to console any message with log level DEBUG or higher and prefixes log type and level to the message.

Appender.Console2=1,5,1,13 11 9 5 3 1

Creates new appender to log to console any message with log level ERROR or higher and prefixes timestamp to the message using colored text.

Appender.File=2,2,7,Auth.log,w

Creates new appender to log to file "Auth.log" any message with log level DEBUG or higher and prefixes timestamp, type and level to message

In the example, having two different loggers to log to console is perfectly legal but redundant.

Comments