XLog::Formatter::Pattern - XLog pattern formatter backend
XLog::set_formatter(XLog::Formatter::Pattern->new("%1t %c[%L/%1M]%C %f:%l,%F(): %m")); XLog::warning("hi");
Default formatter for XLog. Uses strftime-like string syntax to format log messages. Format string is a string with a number of special tokens which will be replaced with additional information.
strftime
Some tokens supports up to 2 modifiers x and y in one of the following formats (given that T is a token): %T or %xT or %x.yT or %.yT
x
y
T
If any of x or y are absent, it is considered 0 (for example %t is the same as %0t and %0.0t). If a token supports modifiers it will be noted below what x and y means.
%t
%0t
%0.0t
Level string ("debug", "info", ...)
Module name
Function name
Filename.
x=0: only filename
x=1: full path as it appeared during loading module (perl) or compilation (C)
Line number
Log message
x=0: normal behaviour
x=1: multiline message support. Each line of message will be "log-formatted" as if they all were written in log separately.
Current time.
Modifier x chooses time format, y chooses microseconds precision
x=0: YYYY-MM-DD HH:MM:SS
x=1: YY-MM-DD HH:MM:SS
x=2: HH:MM:SS
x=3: YYYY/MM/DD HH:MM:SS
x=4: UNIX TIMESTAMP
y>0: high resolution time, adds fractional part after seconds with "y" digits precision
Examples:
%t: 2020-01-31 23:59:59 %2t: 23:59:59 %2.3t: 23:59:59.345
Current thread id. Usually makes sense only for C code or threaded perls.
Current process id.
Current process title. There is a trick, as for Perl interpreter it will always be perl, which makes it senseless. Instead, it spies on $0 and uses that value (transformed via decorator, see below) as process name.
perl
$0
Start colored text. Inserts special control characters and all text after this token will be colored according to log level. Only for unix consoles.
End colored text
Create pattern formatter object
Sets the callback, which will be invoked as
$callback->($0)
to get process name for %P in pattern above.
%P
The callback is invoked only upon $0 changing.
If no decorator has been set, the default one is applied. It will cut script path in $0, leaving only script basename, i.e.
perl path/to/my_script.pl
the $0 will be set to path/to/my_script.pl by default. The default decorator will cut it to:
path/to/my_script.pl
my_script.pl
To install XLog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XLog
CPAN shell
perl -MCPAN -e shell install XLog
For more information on module installation, please visit the detailed CPAN module installation guide.