1Catalyst::Log(3) User Contributed Perl Documentation Catalyst::Log(3)
2
3
4
6 Catalyst::Log - Catalyst Log Class
7
9 $log = $c->log;
10 $log->debug($message);
11 $log->info($message);
12 $log->warn($message);
13 $log->error($message);
14 $log->fatal($message);
15
16 if ( $log->is_debug ) {
17 # expensive debugging
18 }
19
20 See Catalyst.
21
23 This module provides the default, simple logging functionality for
24 Catalyst. If you want something different set "$c->log" in your
25 application module, e.g.:
26
27 $c->log( MyLogger->new );
28
29 Your logging object is expected to provide the interface described
30 here. Good alternatives to consider are Log::Log4Perl and
31 Log::Dispatch.
32
33 If you want to be able to log arbitrary warnings, you can do something
34 along the lines of
35
36 $SIG{__WARN__} = sub { MyApp->log->warn(@_); };
37
38 however this is (a) global, (b) hairy and (c) may have unexpected side
39 effects. Don't say we didn't warn you.
40
42 debug
43 $log->is_debug;
44 $log->debug($message);
45
46 info
47 $log->is_info;
48 $log->info($message);
49
50 warn
51 $log->is_warn;
52 $log->warn($message);
53
54 error
55 $log->is_error;
56 $log->error($message);
57
58 fatal
59 $log->is_fatal;
60 $log->fatal($message);
61
63 new
64 Constructor. Defaults to enable all levels unless levels are provided
65 in arguments.
66
67 $log = Catalyst::Log->new;
68 $log = Catalyst::Log->new( 'warn', 'error' );
69
70 level
71 Contains a bitmask of the currently set log levels.
72
73 levels
74 Set log levels
75
76 $log->levels( 'warn', 'error', 'fatal' );
77
78 enable
79 Enable log levels
80
81 $log->enable( 'warn', 'error' );
82
83 disable
84 Disable log levels
85
86 $log->disable( 'warn', 'error' );
87
88 is_debug
89 is_error
90 is_fatal
91 is_info
92 is_warn
93 Is the log level active?
94
95 abort
96 Should Catalyst emit logs for this request? Will be reset at the end of
97 each request.
98
99 *NOTE* This method is not compatible with other log apis, so if you
100 plan to use Log4Perl or another logger, you should call it like this:
101
102 $c->log->abort(1) if $c->log->can('abort');
103
104 autoflush
105 When enabled (default), messages are written to the log immediately
106 instead of queued until the end of the request.
107
108 This option, as well as "abort", is provided for modules such as
109 Catalyst::Plugin::Static::Simple to be able to programmatically
110 suppress the output of log messages. By turning off "autoflush"
111 (application-wide setting) and then setting the "abort" flag within a
112 given request, all log messages for the given request will be
113 suppressed. "abort" can still be set independently of turning off
114 "autoflush", however. It just means any messages sent to the log up
115 until that point in the request will obviously still be emitted, since
116 "autoflush" means they are written in real-time.
117
118 If you need to turn off autoflush you should do it like this (in your
119 main app class):
120
121 after setup_finalize => sub {
122 my $c = shift;
123 $c->log->autoflush(0) if $c->log->can('autoflush');
124 };
125
126 _send_to_log
127 $log->_send_to_log( @messages );
128
129 This protected method is what actually sends the log information to
130 STDERR. You may subclass this module and override this method to get
131 finer control over the log output.
132
133 psgienv $env
134 $log->psgienv($env);
135
136 NOTE: This is not meant for public consumption.
137
138 Set the PSGI environment for this request. This ensures logs will be
139 sent to the right place. If the environment has a "psgix.logger", it
140 will be used. If not, we will send logs to "psgi.errors" if that
141 exists. As a last fallback, we will send to STDERR as before.
142
143 clear_psgi
144 Clears the PSGI environment attributes set by "psgienv".
145
146 meta
148 Catalyst.
149
151 Catalyst Contributors, see Catalyst.pm
152
154 This library is free software. You can redistribute it and/or modify it
155 under the same terms as Perl itself.
156
157
158
159perl v5.28.1 2019-01-18 Catalyst::Log(3)