1Net::CLI::Interact::LogUgseerr(3C)ontributed Perl DocumeNnetta:t:iCoLnI::Interact::Logger(3)
2
3
4
6 Net::CLI::Interact::Logger - Per-instance multi-target logging, with
7 categories
8
10 $logger->log($category, $level, @message);
11
13 This module implements a generic logging service, based on
14 Log::Dispatch but with additional options and configuration. Log
15 messages coming from your application are categorized, and each
16 category can be enabled/disabled separately and have its own log level
17 (i.e. "emergency" .. "debug"). High resolution timestamps can be added
18 to log messages.
19
21 Being based on Log::Dispatch::Config, this logger can have multiple
22 targets, each configured for independent level thresholds. The overall
23 default configuration is to print log messages to the screen (console),
24 with a minimum level of "debug". Each category (see below) has its own
25 log level as well.
26
27 Note that categories, as discussed below, are arbitrary so if a
28 category is not explicitly enabled or disabled, it is assumed to be
29 disabled. If you wish to invent a new category for your application,
30 simply think of the name and begin to use it, with a $level and
31 @message as above in the SYNOPSIS.
32
34 log( $category, $level, @message )
35 The combination of category and level determine whether the the log
36 messages are emitted to any of the log destinations. Destinations are
37 set using the "log_config" method, and categories are configured using
38 the "log_flags" method.
39
40 The @message list will be joined by a space character, and a newline
41 appended if the last message doesn't contain one itself. Messages are
42 prepended with the first character of their $category, and then
43 indented proportionally to their $level.
44
45 log_config( \%config )
46 A "Log::Dispatch::Config" configuration (hash ref), meaning multiple
47 log targets may be specified with different minimum level thresholds.
48 There is a default configuration which emits messages to your screen
49 (console) with no minimum threshold:
50
51 {
52 dispatchers => ['screen'],
53 screen => {
54 class => 'Log::Dispatch::Screen',
55 min_level => 'debug',
56 },
57 };
58
59 log_flags( \@categories | \%category_level_map )
60 The user is expected to specify which log categories they are
61 interested in, and at what levels. If a category is used in the
62 application for logging but not specified, then it is deemed disabled.
63 Hence, even though the default destination log level is "debug", no
64 messages are emitted until a category is enabled.
65
66 In the array reference form, the list should contain category names,
67 and they will all be mapped to the "error" level:
68
69 $logger->log_flags([qw/
70 network
71 disk
72 io
73 cpu
74 /]);
75
76 In the hash reference form, the keys should be category names and the
77 values log levels from the list below (ordered such that each level
78 "includes" the levels above):
79
80 emergency
81 alert
82 critical
83 error
84 warning
85 notice
86 info
87 debug
88
89 For example:
90
91 $logger->log_flags({
92 network => 'info',
93 disk => 'debug',
94 io => 'critical',
95 cpu => 'debug',
96 });
97
98 Messages at or above the specified level will be passed on to the
99 "Log::Dispatch" target, which may then specify an overriding threshold.
100
101 " Net::CLI::Interact-"default_log_categories() >>
102 Not a part of this class, but the only way to retrieve a list of the
103 current log categories used in the Net::CLI::Interact distribution
104 source. Does not take into account any log categories added by the
105 user.
106
107 log_stamp( $boolean )
108 Enable (the default) or disable the display of high resolution interval
109 timestamps with each log message.
110
111 log_category( $boolean )
112 Enable (the default) or disable the display of the first letters of the
113 category name with each log message.
114
115 log_start( [$seconds, $microseconds] )
116 Time of the start for generating a time interval when logging stamps.
117 Defaults to the result of "Time::HiRes::gettimeofday" at the point the
118 module is loaded, in list context.
119
120 would_log( $category, $level )
121 Returns True if, according to the current "log_flags", the given
122 $category is enabled at or above the threshold of $level, otherwise
123 returns False. Note that the "Log::Dispatch" targets maintain their
124 own thresholds as well.
125
126
127
128perl v5.32.1 2021-01-27 Net::CLI::Interact::Logger(3)