Mail::Reporter is extended by Mail::Box Mail::Box::Collection Mail::Box::Identity Mail::Box::Locker Mail::Box::MH::Index Mail::Box::MH::Labels Mail::Box::Manager Mail::Box::Parser Mail::Box::Search Mail::Box::Thread::Manager Mail::Box::Thread::Node Mail::Message Mail::Message::Body Mail::Message::Body::Delayed Mail::Message::Convert Mail::Message::Field Mail::Message::Field::Attribute Mail::Message::Head Mail::Message::Head::FieldGroup Mail::Message::TransferEnc Mail::Server Mail::Transport
$folder->log(WARNING => 'go away'); print $folder->trace; # current level $folder->trace('PROGRESS'); # set level print $folder->errors; print $folder->report('PROGRESS');
-Option--Default log 'WARNINGS' trace 'WARNINGS'
Known levels are "INTERNAL", "ERRORS", "WARNINGS", "PROGRESS", "NOTICES" "DEBUG", and "NONE". The "PROGRESS" level relates to the reading and writing of folders. "NONE" will cause only "INTERNAL" errors to be logged. By the way: "ERROR" is an alias for "ERRORS", as "WARNING" is an alias for "WARNINGS", and "NOTICE" for "NOTICES".
This method has three different uses. When one argument is specified, that $level is set for both loglevel as tracelevel.
With two arguments, the second determines which configuration you like. If the second argument is a CODE reference, you install a $callback. The loglevel will be set to NONE, and all warnings produced in your program will get passed to the $callback function. That function will get the problem level, the object or class which reports the problem, and the problem text passed as arguments.
In any case two values are returned: the first is the log level, the second represents the trace level. Both are special variables: in numeric context they deliver a value (the internally used value), and in string context the string name. Be warned that the string is always in singular form!
example: setting loglevels
my ($loglevel, $tracelevel) = Mail::Reporter->defaultTrace; Mail::Reporter->defaultTrace('NOTICES'); my ($l, $t) = Mail::Reporter->defaultTrace('WARNINGS', 'DEBUG'); print $l; # prints "WARNING" (no S!) print $l+0; # prints "4" print "Auch" if $l >= $self->logPriority('ERROR'); Mail::Reporter->defaultTrace('NONE'); # silence all reports $folder->defaultTrace('DEBUG'); # Still set as global default! $folder->trace('DEBUG'); # local default
example: installing a callback
Mail::Reporter->defaultTrace
$folder->report('ERRORS')
With one argument, a new level of logging detail is set (specify a number of one of the predefined strings). With more arguments, it is a report which may need to be logged or traced.
As class method, only a message can be passed. The global configuration value set with defaultTrace() is used to decide whether the message is shown or ignored.
Each log-entry has a $level and a text string which will be constructed by joining the $strings. If there is no newline, it will be added.
example:
print $message->log; # may print "NOTICE" print $message->log +0; # may print "3" $message->log('ERRORS'); # sets a new level, returns the numeric value $message->log(WARNING => "This message is too large."); $folder ->log(NOTICE => "Cannot read from file $filename."); $manager->log(DEBUG => "Hi there!", reverse sort @l); Mail::Message->log(ERROR => 'Unknown');
The higher the number, the more important the message. Only messages about "INTERNAL" problems are more important than "NONE".
example:
my $r = Mail::Reporter->logPriority('WARNINGS'); my $r = Mail::Reporter->logPriority('WARNING'); # same my $r = Mail::Reporter->logPriority(4); # same, deprecated print $r; # prints 'WARNING' (no S!) print $r + 0; # prints 4 if($r < Mail::Reporter->logPriority('ERROR')) {..} # true
example:
$head->new($folder->logSettings);
In case no $level is specified, you get all messages each as reference to a tuple with level and message.
example:
my @warns = $message->report('WARNINGS'); # previous indirectly callable with my @warns = $msg->warnings; print $folder->report('ERRORS'); if($folder->report('DEBUG')) {...} my @reports = $folder->report; foreach (@reports) { my ($level, $text) = @$_; print "$level report: $text"; }
example:
my $folder = Mail::Box::Manager->new->open(folder => 'inbox'); my @reports = $folder->reportAll; foreach (@reports) { my ($object, $level, $text) = @$_; if($object->isa('Mail::Box')) { print "Folder $object: $level: $message"; } elsif($object->isa('Mail::Message') { print "Message ".$object->seqnr.": $level: $message"; } }
$folder->report('WARNINGS')
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/