1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
SYNOPSIS
use Log::Any::Adapter;
Log::Any::Adapter->set('ScreenColoredLevel',
# min_level => 'debug', # default is 'warning'
# colors => { trace => 'bold yellow on_gray', ... }, # customize colors
# use_color => 1, # force color even when not interactive
# stderr => 0, # print to STDOUT instead of STDERR
# formatter => sub { "LOG: $_[1]" }, # default none
);
DESCRIPTION
This Log::Any adapter prints log messages to screen (STDERR/STDOUT)
colored according to level. It is just like
Log::Log4perl::Appender::ScreenColoredLevel, even down to the default
colors (with a tiny difference), except that you don't have to use
Log::Log4perl. Of course, unlike Log4perl, it only logs to screen and
has minimal features.
Parameters:
* min_level => STRING
Set logging level. Default is warning. If LOG_LEVEL environment
variable is set, it will be used instead. If TRACE environment
variable is set to true, level will be set to 'trace'. If DEBUG
environment variable is set to true, level will be set to 'debug'. If
VERBOSE environment variable is set to true, level will be set to
'info'.If QUIET environment variable is set to true, level will be
set to 'error'.
* use_color => BOOL
Whether to use color or not. Default is true only when running
interactively (-t STDOUT returns true).
* colors => HASH
Customize colors. Hash keys are the logging methods, hash values are
colors supported by Term::ANSIColor.
The default colors are:
method/level color
------------ -----
trace yellow
debug (none, terminal default)
info, notice green
warning bold blue
error magenta
critical, alert, emergency red
* stderr => BOOL
Whether to print to STDERR, default is true. If set to 0, will print
to STDOUT instead.
* formatter => CODEREF
Allow formatting message. If defined, message will be passed before
being colorized. Coderef will be passed:
($self, $message)
and is expected to return the formatted message.
The default formatter can optionally prefix the message with extra
stuffs, depending on the content of LOG_PREFIX environment variable,
such as: elapsed time (e.g. [0.023ms]) if LOG_PREFIX is elapsed.
NOTE: Log::Any 1.00+ now has a proxy object which allows
formatting/customization of message before it is sent to adapter(s),
so formatting does not have to be done on a per-adapter basis. As an
alternative to this attribute, you can also consider using the proxy
object or the (upcoming?) global proxy object.
ENVIRONMENT
LOG_LEVEL, QUIET, VERBOSE, DEBUG, TRACE. These environment variables
can set the default for min_level. See documentation about min_level
for more details.
LOG_PREFIX. The default formatter groks these variables. See
documentation about formatter about more details.
SEE ALSO
Log::Any
Log::Log4perl::Appender::ScreenColoredLevel
Term::ANSIColor
|