… | |
… | |
191 | |
191 | |
192 | Last not least, C<$msg> might be a code reference, in which case it is |
192 | Last not least, C<$msg> might be a code reference, in which case it is |
193 | supposed to return the message. It will be called only then the message |
193 | supposed to return the message. It will be called only then the message |
194 | actually gets logged, which is useful if it is costly to create the |
194 | actually gets logged, which is useful if it is costly to create the |
195 | message in the first place. |
195 | message in the first place. |
|
|
196 | |
|
|
197 | This function takes care of saving and restoring C<$!> and C<$@>, so you |
|
|
198 | don't have to. |
196 | |
199 | |
197 | Whether the given message will be logged depends on the maximum log level |
200 | Whether the given message will be logged depends on the maximum log level |
198 | and the caller's package. The return value can be used to ensure that |
201 | and the caller's package. The return value can be used to ensure that |
199 | messages or not "lost" - for example, when L<AnyEvent::Debug> detects a |
202 | messages or not "lost" - for example, when L<AnyEvent::Debug> detects a |
200 | runtime error it tries to log it at C<die> level, but if that message is |
203 | runtime error it tries to log it at C<die> level, but if that message is |
… | |
… | |
300 | } |
303 | } |
301 | |
304 | |
302 | # log if log cb |
305 | # log if log cb |
303 | if ($ctx->[3]) { |
306 | if ($ctx->[3]) { |
304 | # logging target found |
307 | # logging target found |
|
|
308 | |
|
|
309 | local ($!, $@); |
305 | |
310 | |
306 | # now get raw message, unless we have it already |
311 | # now get raw message, unless we have it already |
307 | unless ($now) { |
312 | unless ($now) { |
308 | $format = $format->() if ref $format; |
313 | $format = $format->() if ref $format; |
309 | $format = sprintf $format, @args if @args; |
314 | $format = sprintf $format, @args if @args; |