NAME
XLog::Formatter::Pattern - XLog pattern formatter backend
SYNPOSIS
XLog::set_formatter(XLog::Formatter::Pattern->new("%1t %c[%L/%1M]%C %f:%l,%F(): %m"));
XLog::warning("hi");
DESCRIPTION
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.
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
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.
- %L
-
Level string ("debug", "info", ...)
- %M
-
Module name
- %F
-
Function name
- %f
-
Filename.
x=0: only filename
x=1: full path as it appeared during loading module (perl) or compilation (C)
- %l
-
Line number
- %m
-
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.
- %t
-
Current time.
Modifier
x
chooses time format,y
chooses microseconds precisionx=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
- %T
-
Current thread id. Usually makes sense only for C code or threaded perls.
- %p
-
Current process id.
- %P
-
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. - %c
-
Start colored text. Inserts special control characters and all text after this token will be colored according to log level. Only for unix consoles.
- %C
-
End colored text
METHODS
new($format)
Create pattern formatter object
FUNCTIONS
set_program_decorator($callback)
Sets the callback, which will be invoked as
$callback->($0)
to get process name for %P
in pattern above.
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:
my_script.pl