.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Log 3pm" .TH Mojo::Log 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Log \- Simple logger .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Log; \& \& # Log to STDERR \& my $log = Mojo::Log\->new; \& \& # Customize log file location and minimum log level \& my $log = Mojo::Log\->new(path => \*(Aq/var/log/mojo.log\*(Aq, level => \*(Aqwarn\*(Aq); \& \& # Log messages \& $log\->debug(\*(AqNot sure what is happening here\*(Aq); \& $log\->info(\*(AqFYI: it happened again\*(Aq); \& $log\->warn(\*(AqThis might be a problem\*(Aq); \& $log\->error(\*(AqGarden variety error\*(Aq); \& $log\->fatal(\*(AqBoom\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Log is a simple logger for Mojo projects. .SH "EVENTS" .IX Header "EVENTS" Mojo::Log inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS "message" .IX Subsection "message" .Vb 4 \& $log\->on(message => sub { \& my ($log, $level, @lines) = @_; \& ... \& }); .Ve .PP Emitted when a new message gets logged. .PP .Vb 4 \& $log\->on(message => sub { \& my ($log, $level, @lines) = @_; \& say "$level: ", @lines; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Log implements the following attributes. .SS "format" .IX Subsection "format" .Vb 2 \& my $cb = $log\->format; \& $log = $log\->format(sub {...}); .Ve .PP A callback for formatting log messages. .PP .Vb 4 \& $log\->format(sub { \& my ($time, $level, @lines) = @_; \& return "[2018\-11\-08 14:20:13.77168] [28320] [info] I ♥ Mojolicious\en"; \& }); .Ve .SS "handle" .IX Subsection "handle" .Vb 2 \& my $handle = $log\->handle; \& $log = $log\->handle(IO::Handle\->new); .Ve .PP Log filehandle used by default \*(L"message\*(R" event, defaults to opening \&\*(L"path\*(R" or \f(CW\*(C`STDERR\*(C'\fR. .SS "history" .IX Subsection "history" .Vb 2 \& my $history = $log\->history; \& $log = $log\->history([[time, \*(Aqdebug\*(Aq, \*(AqThat went wrong\*(Aq]]); .Ve .PP The last few logged messages. .SS "level" .IX Subsection "level" .Vb 2 \& my $level = $log\->level; \& $log = $log\->level(\*(Aqdebug\*(Aq); .Ve .PP Active log level, defaults to \f(CW\*(C`debug\*(C'\fR. Available log levels are \f(CW\*(C`debug\*(C'\fR, \&\f(CW\*(C`info\*(C'\fR, \f(CW\*(C`warn\*(C'\fR, \f(CW\*(C`error\*(C'\fR and \f(CW\*(C`fatal\*(C'\fR, in that order. .SS "max_history_size" .IX Subsection "max_history_size" .Vb 2 \& my $size = $log\->max_history_size; \& $log = $log\->max_history_size(5); .Ve .PP Maximum number of logged messages to store in \*(L"history\*(R", defaults to \f(CW10\fR. .SS "path" .IX Subsection "path" .Vb 2 \& my $path = $log\->path \& $log = $log\->path(\*(Aq/var/log/mojo.log\*(Aq); .Ve .PP Log file path used by \*(L"handle\*(R". .SS "short" .IX Subsection "short" .Vb 2 \& my $bool = $log\->short; \& $log = $log\->short($bool); .Ve .PP Generate short log messages without a timestamp, suitable for systemd, defaults to the value of the \f(CW\*(C`MOJO_LOG_SHORT\*(C'\fR environment variables. .SH "METHODS" .IX Header "METHODS" Mojo::Log inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS "append" .IX Subsection "append" .Vb 1 \& $log\->append("[2018\-11\-08 14:20:13.77168] [28320] [info] I ♥ Mojolicious\en"); .Ve .PP Append message to \*(L"handle\*(R". .SS "debug" .IX Subsection "debug" .Vb 3 \& $log = $log\->debug(\*(AqYou screwed up, but that is ok\*(Aq); \& $log = $log\->debug(\*(AqAll\*(Aq, \*(Aqcool\*(Aq); \& $log = $log\->debug(sub {...}); .Ve .PP Emit \*(L"message\*(R" event and log \f(CW\*(C`debug\*(C'\fR message. .SS "error" .IX Subsection "error" .Vb 3 \& $log = $log\->error(\*(AqYou really screwed up this time\*(Aq); \& $log = $log\->error(\*(AqWow\*(Aq, \*(Aqseriously\*(Aq); \& $log = $log\->error(sub {...}); .Ve .PP Emit \*(L"message\*(R" event and log \f(CW\*(C`error\*(C'\fR message. .SS "fatal" .IX Subsection "fatal" .Vb 3 \& $log = $log\->fatal(\*(AqIts over...\*(Aq); \& $log = $log\->fatal(\*(AqBye\*(Aq, \*(Aqbye\*(Aq); \& $log = $log\->fatal(sub {...}); .Ve .PP Emit \*(L"message\*(R" event and log \f(CW\*(C`fatal\*(C'\fR message. .SS "info" .IX Subsection "info" .Vb 3 \& $log = $log\->info(\*(AqYou are bad, but you prolly know already\*(Aq); \& $log = $log\->info(\*(AqOk\*(Aq, \*(Aqthen\*(Aq); \& $log = $log\->info(sub {...}); .Ve .PP Emit \*(L"message\*(R" event and log \f(CW\*(C`info\*(C'\fR message. .SS "is_level" .IX Subsection "is_level" .Vb 1 \& my $bool = $log\->is_level(\*(Aqdebug\*(Aq); .Ve .PP Check active log \*(L"level\*(R". .PP .Vb 3 \& # True \& $log\->level(\*(Aqdebug\*(Aq)\->is_level(\*(Aqdebug\*(Aq); \& $log\->level(\*(Aqdebug\*(Aq)\->is_level(\*(Aqinfo\*(Aq); \& \& # False \& $log\->level(\*(Aqinfo\*(Aq)\->is_level(\*(Aqdebug\*(Aq); \& $log\->level(\*(Aqfatal\*(Aq)\->is_level(\*(Aqwarn\*(Aq); .Ve .SS "new" .IX Subsection "new" .Vb 3 \& my $log = Mojo::Log\->new; \& my $log = Mojo::Log\->new(level => \*(Aqwarn\*(Aq); \& my $log = Mojo::Log\->new({level => \*(Aqwarn\*(Aq}); .Ve .PP Construct a new Mojo::Log object and subscribe to \*(L"message\*(R" event with default logger. .SS "warn" .IX Subsection "warn" .Vb 3 \& $log = $log\->warn(\*(AqDont do that Dave...\*(Aq); \& $log = $log\->warn(\*(AqNo\*(Aq, \*(Aqreally\*(Aq); \& $log = $log\->warn(sub {...}); .Ve .PP Emit \*(L"message\*(R" event and log \f(CW\*(C`warn\*(C'\fR message. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .