Log-Handler-0.90/ 0000750 0000000 0000000 00000000000 13702611501 012223 5 ustar root root Log-Handler-0.90/README 0000644 0000000 0000000 00000074177 13702611501 013130 0 ustar root root NAME
Log::Handler - Log messages to several outputs.
SYNOPSIS
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
file => {
filename => "file.log",
maxlevel => "debug",
minlevel => "warning",
}
);
$log->warning("message");
Or
use Log::Handler;
my $log = Log::Handler->new(
screen => {
log_to => "STDOUT",
maxlevel => "debug",
minlevel => "debug",
message_layout => "%T [%L] %m (%C)",
},
screen => {
log_to => "STDOUT",
maxlevel => "info",
minlevel => "notice",
},
screen => {
log_to => "STDERR",
maxlevel => "warning",
minlevel => "emergency",
},
);
Or
use Log::Handler;
my $log = Log::Handler->new();
$log->config( config => "logger.conf" );
# and maybe later
$log->reload( config => "logger.conf" );
Or
# create a application wide logger
package MyApp;
use Log::Handler;
my $log = Log::Handler->create_logger("myapp");
$log->add(screen => { maxlevel => "info" });
$log->info("info message");
# get logger with get_logger()
package MyApp::Admin;
use Log::Handler;
my $log = Log::Handler->get_logger("myapp");
$log->info("info message from MyApp::Admin");
DESCRIPTION
The Log::Handler is a object oriented handler for logging, tracing and
debugging. It is very easy to use and provides a simple interface for
multiple output objects with lots of configuration parameters. You can
easily filter the amount of logged information on a per-output base,
define priorities, create patterns to format the messages and reload
the complete logging machine.
See the documentation for details.
IMPORTANT NOTES
Note that the default for option newline is now set to TRUE and
newlines will be appended automatically to each message if no newline
exists.
A long time I thought about this serious change and have come to the
decision to change it.
The default for option mode from Log::Handler::Output::File is now
append and not excl anymore.
The methods reload() and validate() are new since version 0.62. I
tested it with Screen.pm, File.pm and DBI.pm and it runs fine. If you
find bugs then open a bug report please :-)
LOG LEVELS
There are eigth levels available:
7 debug
6 info
5 notice
4 warning, warn
3 error, err
2 critical, crit
1 alert
0 emergency, emerg
debug is the highest and emergency is the lowest level.
Level debug is the highest level because it basically says to log every
peep.
LOG LEVEL METHODS
Level methods
debug()
info()
notice()
warning(), warn()
error(), err()
critical(), crit()
alert()
emergency(), emerg()
The call of a log level method is very simple:
$log->info("Hello World! How are you?");
Or maybe:
$log->info("Hello World!", "How are you?");
Both calls would log - if level INFO is active:
Feb 01 12:56:31 [INFO] Hello World! How are you?
is_* methods
is_debug()
is_info()
is_notice()
is_warning(), is_warn()
is_error(), is_err()
is_critical(), is_crit()
is_alert()
is_emergency(), is_emerg()
These twelve methods could be very useful if you want to kwow if the
current level would log the message. All methods returns TRUE if the
current set of minlevel and maxlevel would log the message and FALSE if
not.
SPECIAL LOG METHODS
fatal, is_fatal
trace
dump
die
log
For a full list take a look into the documentation of
Log::Handler::Levels.
METHODS
new()
Call new() to create a new log handler object.
my $log = Log::Handler->new();
add()
Call add() to add a new output object.
The method expects 2 parts of options; the options for the handler and
the options for the output module you want to use. The output modules
got it's own documentation for all options.
Example:
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
# Add "file output"
file => {
# handler options (see Log::Handler)
timeformat => "%Y/%m/%d %H:%M:%S",
message_layout => "%T [%L] %S: %m",
maxlevel => "debug",
minlevel => "emergency",
die_on_errors => 1,
debug_trace => 0,
debug_mode => 2,
debug_skip => 0,
# file options (see Log::Handler::Output::File)
filename => "file.log",
filelock => 1,
fileopen => 1,
reopen => 1,
autoflush => 1,
permissions => "0660",
utf8 => 1,
}
);
Take a look to Log::Handler::Examples for more examples.
The following options are possible for the handler:
maxlevel and minlevel
With these options it's possible to set the log levels for your
program.
Example:
maxlevel => "error"
minlevel => "emergency"
# or
maxlevel => "err"
minlevel => "emerg"
# or
maxlevel => 3
minlevel => 0
It's possible to set the log level as string or as number. The
default setting for maxlevel is warning and the default setting for
minlevel is emergency.
Example: If maxlevel is set to warning and minlevel to emergency then
the levels warning, error, critical, alert and emergency would be
logged.
You can set both to 8 or nothing if you want to disable the logging
machine.
timeformat
The option timeformat is used to set the format for the placeholder
%T. The string is converted with POSIX::strftime. The default format
is set to "%b %d %H:%M:%S" and looks like
Feb 01 12:56:31
If you would set the format to "%Y/%m/%d %H:%M:%S" it would looks
like
2007/02/01 12:56:31
dateformat
This options works like timeformat. You can set a format that is used
for the placeholder %D. It's just useful if you want to split the
date and time:
$log->add(file => {
filename => "file.log",
dateformat => "%Y-%m-%d",
timeformat => "%H:%M:%S",
message_layout => "%D %T %L %m",
});
$log->error("an error here");
This looks like
2007-02-01 12:56:31 ERROR an error here
This option is not used by default.
newline
newline is a very helpful option. It let the logger appends a newline
to the message if a newline doesn't exist.
0 - do nothing
1 - append a newline if not exist (default)
Example:
$log->add(
screen => {
newline => 1,
maxlevel => "info",
}
);
$log->info("message\n");
$log->info("message");
In both cases the message would be logged with a newline at the end.
message_layout
With this option it's possible to create your own message layout with
different placeholders in printf() style. The available placeholders
are:
%L Log level
%T Time or full timestamp (option timeformat)
%D Date (option dateformat)
%P PID
%H Hostname
%U User name
%G Group name
%N Newline
%S Program name
%C Caller - filename and line number
%p Caller - package name
%f Caller - file name
%l Caller - line number
%s Caller - subroutine name
%r Runtime in seconds since program start
%t Time measurement - replaced with the time since the last call of $log->$level
%m Message
%% Percent
The default message layout is set to "%T [%L] %m".
As example the following code
$log->alert("foo bar");
would log
Feb 01 12:56:31 [ALERT] foo bar
If you set message_layout to
message_layout => "%T foo %L bar %m (%C)"
and call
$log->info("baz");
then it would log
Feb 01 12:56:31 foo INFO bar baz (script.pl, line 40)
Traces will be appended after the complete message.
You can create your own placeholders with the method set_pattern().
message_pattern
This option is just useful if you want to forward messages to output
modules that needs the parts of a message as a hash reference - as
example Log::Handler::Output::Forward, Log::Handler::Output::DBI or
Log::Handler::Output::Screen.
The option expects a list of placeholders:
# as a array reference
message_pattern => [ qw/%T %L %H %m/ ]
# or as a string
message_pattern => "%T %L %H %m"
The patterns will be replaced with real names as hash keys.
%L level
%T time
%D date
%P pid
%H hostname
%U user
%G group
%N newline
%r runtime
%C caller
%p package
%f filename
%l line
%s subroutine
%S progname
%t mtime
%m message
Here a full code example:
use Log::Handler;
my $log = Log::Handler->new();
$log->add(forward => {
forward_to => \&my_func,
message_pattern => [ qw/%T %L %H %m/ ],
message_layout => "%m",
maxlevel => "info",
});
$log->info("a forwarded message");
# now you can access it
sub my_func {
my $msg = shift;
print "Timestamp: $msg->{time}\n";
print "Level: $msg->{level}\n";
print "Hostname: $msg->{hostname}\n";
print "Message: $msg->{message}\n";
}
prepare_message
prepare_message is useful if you want to do something with the
message before it will be logged... maybe you want to create your own
layout because message_layout doesn't meet your claim.
$log->add(
screen => {
newline => 1,
message_layout => "%m (%t)",
message_pattern => [ qw/%T %L %H %m/ ],
prepare_message => \&format,
}
);
$log->error("foo");
$log->error("bar");
$log->error("baz");
sub format {
my $m = shift;
$m->{message} = sprintf("%-20s %-20s %-20s %s",
$m->{time}, $m->{level}, $m->{hostname}, $m->{message});
}
The output looks like
Mar 08 15:14:20 ERROR h1434036 foo (0.039694)
Mar 08 15:14:20 ERROR h1434036 bar (0.000510)
Mar 08 15:14:20 ERROR h1434036 baz (0.000274)
priority
With this option you can set the priority of your output objects.
This means that messages will be logged at first to the outputs with
a higher priority. If this option is not set then the default
priority begins with 10 and will be increased +1 with each output.
Example:
We add a output with no priority
$log->add(file => { filename => "file1.log" });
This output gets the priority of 10. Now we add another output
$log->add(file => { filename => "file2.log" });
This output gets the priority of 11... and so on.
Messages would be logged at first to the output with the priority of
10 and then to the output with the priority of 11. Now you can add
another output and set the priority to 1.
$log->add(screen => { dump => 1, priority => 1 });
Messages would be logged now at first to the screen.
die_on_errors
Set die_on_errors to 0 if you don't want that the handler dies on
failed write operations.
0 - to disable it
1 - to enable it
If you set die_on_errors to 0 then you have to control it yourself.
$log->info("info message") or die $log->errstr();
# or Log::Handler->errstr()
# or Log::Handler::errstr()
# or $Log::Handler::ERRSTR
remove_on_reload
This option is set to 1 by default.
Take a look to the description of the method reload for more
information about this option.
filter_message
With this option it's possible to set a filter. If the filter is set
then only messages will be logged that match the filter. You can pass
a regexp, a code reference or a simple string. Example:
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => qr/log this/,
# or
# filter_message => "log this",
# filter_message => '^log only this$',
});
$log->info("log this");
$log->info("but not that");
If you pass your own code then you have to check the message
yourself.
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => \&my_filter
});
# return TRUE if you want to log the message, FALSE if not
sub my_filter {
my $msg = shift;
$msg->{message} =~ /your filter/;
}
It's also possible to define a simple condition with matches. Just
pass a hash reference with the options matchN and condition. Example:
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => {
match1 => "log this",
match2 => qr/with that/,
match3 => "(?:or this|or that)",
condition => "(match1 && match2) || match3",
}
});
NOTE that re-eval in regexes is not valid! Something like
match1 => '(?{unlink("file.txt")})'
would cause an error!
skip_message
This is the opposite of option filter_message, but it's only possible
to set a simple string or regular expression.
$log->add(file => {
filename => "file.log",
maxlevel => 6,
skip => '^do not log this.+$'
});
category
The parameter category works like filter_caller but is much easier to
configure. You can set a comma separated list of modules. As example
if you would set the category to
category => "MyApp::User"
then all messages of MyApp::User and the submodules would be logged.
Example:
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => "info",
category => "MyApp::User, MyApp::Session"
}
);
package MyApp;
$log->info(__PACKAGE__);
package MyApp::Products;
$log->info(__PACKAGE__);
package MyApp::User;
$log->info(__PACKAGE__);
package MyApp::Users;
$log->info(__PACKAGE__);
package MyApp::User::Settings;
$log->info(__PACKAGE__);
package MyApp::Session;
$log->info(__PACKAGE__);
package MyApp::Session::Settings;
$log->info(__PACKAGE__);
The messages of MyApp and MyApp::Products would not be logged.
The usage of categories is much faster than to filter by caller.
filter_caller
You can use this option to set a package name. Only messages from
this packages will be logged.
Example:
my $log = Log::Handler->new();
$log->add(screen => {
maxlevel => "info",
filter_caller => qr/^Foo::Bar\z/,
# or
# filter_caller => "^Foo::Bar\z",
});
package Foo::Bar;
$log->info("log this");
package Foo::Baz;
$log->info("but not that");
1;
This would only log the message from the package Foo::Bar.
except_caller
This option is just the opposite of filter_caller.
If you want to log messages from all callers but Foo::Bar:
except_caller => qr/^Foo::Bar\z/
alias
You can set an alias if you want to get the output object later.
Example:
my $log = Log::Handler->new();
$log->add(screen => {
maxlevel => 7,
alias => "screen-out",
});
my $screen = $log->output("screen-out");
$screen->log(message => "foo");
# or in one step
$log->output("screen-out")->log(message => "foo");
debug_trace
You can activate a debugger that writes caller() information about
each active log level. The debugger is logging all defined values
except hints and bitmask. Set debug_trace to 1 to activate the
debugger. The debugger is set to 0 by default.
debug_mode
There are two debug modes: line(1) and block(2) mode. The default
mode is 1.
The line mode looks like this:
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new()
$log->add(file => {
filename => "*STDOUT",
maxlevel => "debug",
debug_trace => 1,
debug_mode => 1
});
sub test1 { $log->warning() }
sub test2 { &test1; }
&test2;
Output:
Apr 26 12:54:11 [WARNING]
CALL(4): package(main) filename(./trace.pl) line(15) subroutine(main::test2) hasargs(0)
CALL(3): package(main) filename(./trace.pl) line(13) subroutine(main::test1) hasargs(0)
CALL(2): package(main) filename(./trace.pl) line(12) subroutine(Log::Handler::__ANON__) hasargs(1)
CALL(1): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(713) subroutine(Log::Handler::_write) hasargs(1)
CALL(0): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(1022) subroutine(Devel::Backtrace::new) hasargs(1) wantarray(0)
The same code example but the debugger in block mode would looks like
this:
debug_mode => 2
Output:
Apr 26 12:52:17 [DEBUG]
CALL(4):
package main
filename ./trace.pl
line 15
subroutine main::test2
hasargs 0
CALL(3):
package main
filename ./trace.pl
line 13
subroutine main::test1
hasargs 0
CALL(2):
package main
filename ./trace.pl
line 12
subroutine Log::Handler::__ANON__
hasargs 1
CALL(1):
package Log::Handler
filename /usr/local/share/perl/5.8.8/Log/Handler.pm
line 681
subroutine Log::Handler::_write
hasargs 1
CALL(0):
package Log::Handler
filename /usr/local/share/perl/5.8.8/Log/Handler.pm
line 990
subroutine Devel::Backtrace::new
hasargs 1
wantarray 0
debug_skip
This option let skip the caller() information the count of
debug_skip.
output()
Call output($alias) to get the output object that you added with the
option alias.
It's possible to access a output directly:
$log->output($alias)->log(message => "booo");
For more information take a look to the option alias.
flush()
Call flush() if you want to send flush to all outputs that can flush.
Flush means to flush buffers and/or close and re-open outputs.
If you want to send it only to some outputs you can pass the aliases.
$log->flush(); # flush all
$log->flush("foo", "bar"); # flush only foo and bar
If option "die_on_errors" is set to 0 then you can intercept errors
with:
$log->flush or die $log->errstr;
errstr()
Call errstr() if you want to get the last error message. This is useful
if you set die_on_errors to 0 and the handler wouldn't die on failed
write operations.
use Log::Handler;
my $log = Log::Handler->new();
$log->add(file => {
filename => "file.log",
maxlevel => "info",
die_on_errors => 0,
});
$log->info("Hello World!") or die $log->errstr;
Or
unless ( $log->info("Hello World!") ) {
$error_string = $log->errstr;
# do something with $error_string
}
The exception is that the handler dies in any case if the call of new()
or add() fails because on missing or wrong settings!
config()
With this method it's possible to load your output configuration from a
file.
$log->config(config => "file.conf");
Or
$log->config(config => {
file => [
{
alias => "error_log",
filename => "error.log",
maxlevel => "warning",
minlevel => "emerg",
priority => 1
},
{
alias => "common_log",
filename => "common.log",
maxlevel => "info",
minlevel => "emerg",
priority => 2
},
],
screen => {
alias => "screen",
maxlevel => "debug",
minlevel => "emerg",
log_to => "STDERR",
},
});
The key "default" is used here to define default parameters for all
file outputs. All other keys (error_log, common_log) are used as
aliases.
Take a look into the documentation of Log::Handler::Config for more
information.
reload()
With the method reload() it's possible to reload the logging machine.
Just pass the complete new configuration for all outputs, it works
exaclty like config().
At first you should know that it's highly recommended to set a alias
for each output. If you don't set a alias then the logger doesn't know
which output-objects to reload. If a output-objects doesn't have a
alias then the objects will be removed and the new configuration will
be added.
Example:
logger.conf
alias = debug
filename = debug.log
maxlevel = debug
minlevel = emerg
alias = common
filename = common.log
maxlevel = info
minlevel = emerg
Load the configuration
$log->config(config => "logger.conf");
Now change the configuration in logger.conf
alias = common
filename = common.log
maxlevel = notice
minlevel = emerg
alias = sendmail
from = bar@foo.example
to = foo@bar.example
subject = your subject
What happends now...
The file-output with the alias debug will be removed, the file-output
with the alias common will be reloaded and the output with the alias
sendmail will be added.
If you don't want that output-objects will be removed because they were
added internal, then you can set the option remove_on_reload to 0.
Example:
$log->config(config => "logger.conf");
$log->add(
forward => {
forward_to => \&my_func,
remove_on_reload => 0,
}
);
The forward-output is not removed after a reload.
validate()
The method validate() expects the same arguments like config() and
reload().
Maybe you want to validate your options before you pass them to
config() or reload().
Example:
my $log = Log::Handler->new();
$log->config( config => \%config );
# and maybe later
if ( $log->validate( config => \%new_config ) ) {
$log->reload( config => \%new_config );
} else {
warn "unable to reload configuration";
warn $log->errstr;
}
set_pattern()
With this option you can set your own placeholders. Example:
$log->set_pattern("%X", "key_name", sub { "value" });
# or
$log->set_pattern("%X", "key_name", "value");
Then you can use this pattern in your message layout:
$log->add(file => {
filename => "file.log",
message_layout => "%X %m%N",
});
Or use it with message_pattern:
sub func {
my $m = shift;
print "$m->{key_name} $m->{message}\n";
}
$log->add(forward => {
forward_to => \&func,
message_pattern => "%X %m",
});
Note: valid character for the key name are: [%\w\-\.]+
set_level()
With this method it's possible to change the log level at runtime.
To change the log level it's necessary to use a alias - see option
alias.
$log->set_level(
$alias => { # option alias
minlevel => $new_minlevel,
maxlevel => $new_maxlevel,
}
);
set_default_param()
With this methods it's possible to overwrite the default settings for
new outputs.
Normally you would do something like
$log->add(
file => {
filename => "debug.log",
maxlevel => "info",
timeformat => "%b %d %Y %H:%M:%S",
message_layout => "[%T] %L %P %t %m (%C)"
}
);
$log->add(
file => {
filename => "error.log",
maxlevel => "error",
timeformat => "%b %d %Y %H:%M:%S",
message_layout => "[%T] %L %P %t %m (%C)"
}
);
Now you can simplify it with
$log->set_default_param(
timeformat => "%b %d %Y %H:%M:%S",
message_layout => "[%T] %L %P %t %m (%C)"
);
$logg->add(
file => {
filename => "debug.log",
maxlevel => "info"
}
);
$log->add(
file => {
filename => "error.log",
maxlevel => "error"
}
);
create_logger()
create_logger() is the same like new() but it creates a global logger.
my $log = Log::Handler->create_logger("myapp");
get_logger()
With get_logger() it's possible to get a logger that was created with
create_logger() or with
use Log::Handler "myapp";
Just call
my $log = Log::Handler->get_logger("myapp");
If the logger does not exists then a new logger will be created and
returned.
exists_logger()
With exists_logger() it's possible to check if a logger exists and it
returns TRUE or FALSE.
EXAMPLES
Log::Handler::Examples
BENCHMARK
The benchmark (examples/benchmark/benchmark.pl) runs on a Intel Core
i7-920 with the following result:
simple pattern output took : 1 wallclock secs ( 1.26 usr + 0.01 sys = 1.27 CPU) @ 78740.16/s (n=100000)
default pattern output took : 2 wallclock secs ( 2.08 usr + 0.15 sys = 2.23 CPU) @ 44843.05/s (n=100000)
complex pattern output took : 4 wallclock secs ( 3.22 usr + 0.23 sys = 3.45 CPU) @ 28985.51/s (n=100000)
message pattern output took : 3 wallclock secs ( 2.72 usr + 0.16 sys = 2.88 CPU) @ 34722.22/s (n=100000)
suppressed output took : 0 wallclock secs ( 0.08 usr + 0.00 sys = 0.08 CPU) @ 1250000.00/s (n=100000)
filtered caller output took : 2 wallclock secs ( 2.10 usr + 0.68 sys = 2.78 CPU) @ 35971.22/s (n=100000)
suppressed caller output took : 1 wallclock secs ( 0.54 usr + 0.00 sys = 0.54 CPU) @ 185185.19/s (n=100000)
filtered messages output took : 3 wallclock secs ( 2.62 usr + 0.08 sys = 2.70 CPU) @ 37037.04/s (n=100000)
EXTENSIONS
Send me a mail if you have questions.
PREREQUISITES
Prerequisites for all modules:
Carp
Data::Dumper
Fcntl
Params::Validate
POSIX
Time::HiRes
Sys::Hostname
UNIVERSAL
Recommended modules:
Config::General
Config::Properties
DBI
IO::Socket
Net::SMTP
YAML
Just for the test suite:
File::Spec
Test::More
EXPORTS
No exports.
REPORT BUGS
Please report all bugs to .
AUTHOR
Jonny Schulz .
QUESTIONS
Do you have any questions or ideas?
MAIL:
IRC: irc.perl.org#perl
If you send me a mail then add Log::Handler into the subject.
COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Log-Handler-0.90/Makefile.PL 0000644 0000000 0000000 00000001240 13702611501 014177 0 ustar root root # Note: this file was auto-generated by Module::Build::Compat version 0.4224
use ExtUtils::MakeMaker;
WriteMakefile
(
'INSTALLDIRS' => 'site',
'EXE_FILES' => [],
'PL_FILES' => {},
'NAME' => 'Log::Handler',
'VERSION_FROM' => 'lib/Log/Handler.pm',
'PREREQ_PM' => {
'Test::More' => 0,
'Params::Validate' => 0,
'Sys::Hostname' => 0,
'Data::Dumper' => 0,
'File::Spec' => 0,
'Carp' => 0,
'Time::HiRes' => 0,
'Fcntl' => 0,
'UNIVERSAL' => 0,
'POSIX' => 0
}
)
;
Log-Handler-0.90/ChangeLog 0000640 0000000 0000000 00000050735 13702611430 014011 0 ustar root root 0.90 Released at 2020-07-12.
- Fixed call of Sys::Hostname::hostname.
0.88 Released at 2016-08-08.
- Just fixed meta data.
0.87 Released at 2015-06-16.
- Implemented new option skip_message.
0.86 Released at 2015-06-12.
- Quick fix for dateext and fileopen.
0.85 Released at 2015-06-12.
- Added parameter dateext to Output::File.
0.84 Released at 2014-10-24.
- Fixed some version conflicts.
0.83 Released at 2014-10-23.
- Added method set_default_param.
0.82 Released at 2013-11-03.
- Fixed the calls of _raise_error (RT #89989).
0.81 Released at 2013-11-01.
- Added param utf-8 to Screen.pm and File.pm.
0.80 Released at 2013-10-04.
- Fixed RT #89250 - dump() calls Dumper() now only if the log
level is active.
0.79 Released at 2013-09-06.
- Added option "category".
0.78 Released at 2013-05-16.
- Fixed bug in validate->reload for default configs (RT #85346).
0.77 Released at 2013-05-15.
- Just fixed Pod::Coverage testing in 002-pod-coverage.t.
0.76 Released at 2012-11-19.
- Fixed dbi_handle in DBI.pm (RT #81155).
0.75 Released at 2012-03-09.
- Quick fix and replaced the "defined or" operator // with || in
Pattern.pm, line 101 for backward compability with Perl < 5.10.
Thanks to all CPAN smoker for the fix test reports!
0.74 Released at 2012-03-07.
- Removed "main" from _get_c_sub if caller returns undef.
Sorry, that was just for debugging :/
- 3 releases at one day... GRML
0.73 Released at 2012-03-07.
- Improved _get_c_sub in Pattern.pm (RT #75596).
0.72 Released at 2012-03-07.
- Some code improvements to tune Log::Handler.
Each value that is passed to set_pattern and is not code
will be embedded into sub{}.
- Add option utf8 to Screen.pm (RT #75593).
0.71 Released at 2011-02-10.
- Fixed RT#65515 and added dateformat to _split_options().
0.70 Released at 2011-01-07.
- Added exists_logger().
- get_logger() doesn't croak any more if a logger
doesn't exists.
0.69 Released at 2010-12-11.
- Just a full release.
0.68_01 Released at 2010-12-07.
- Added option dbi_handle to DBI.pm.
- Bug fix RT #63687.
0.68 Released at 2010-11-24.
- Fixed a bug in add(). It wasn't possible to pass more
than one output configuration to add().
0.67 Released at 2010-10-10.
- Fixed a bug in set_level. The new level was set correctly
but no message was logged because the output wasn't added
to the $self->{levels} array.
0.66 Released at 2010-09-27.
- Roled back again to 0.65 for different reasons.
- Fixed some spelling error in POD (RT #60005).
- It's not possible any more to create or get
more than one logger with get_logger() and
create_logger().
0.65_04 Released at 2010-09-07.
- Fixed a bug with filter_output in Log::Handler
and Log::Handler::Output.
0.65_03 Released at 2010-08-27.
- Added option filter (unused since 2008-07-25).
- Added method filter().
0.65_02 Released at 2010-08-16.
- Rollbacked to 0.65 :-)
- Fixed some spelling error in POD (RT #60005).
- Added option category that works like filter_caller
but it's nicer to configure.
0.65_01 Released at 2010-08-03.
- Modified create_logger and get_logger and added
the functionalety to create and fetch category loggers.
- Fixed some spelling error in POD (RT #60005).
0.65 Released at 2010-08-02.
- Modified Log::Handler::Output::DBI. Oracle is unable
to handle "select 1". The statement is changed to
"select 1 from dual".
0.64 Released at 2010-01-29.
- Fixed a bug in Email.pm on line 256 - $string can be
uninitialized.
0.63 Released at 2009-11-24.
- Fixed a typo in Email.pm (RT #51745).
- Added options cc and bcc to Email.pm - this was a
feature request.
- It's now possible to pass the log level to log()
of Sendmail.pm.
0.62 Released at 2009-11-06.
- Some bug fixes for reload() but it should run now :-)
0.61_04 Released at 2009-11-04.
- Fixed a little bug in Sendmail.pm - the tests returns
an error if no /usr/sbin/sendmail is found.
- Some code improvements in Handler.pm.
0.61_03 Released at 2009-11-01.
- Added a validate() functionality. It's really
useable to validate() before reload().
0.61_02 Released at 2009-11-01.
- Fixed a bug in Email.pm - $options -> $opts.
- Made some code improvements in Log::Handler.
- Added reload() to the test suite.
- Added UNIVERSAL to the dependencies.
0.61_01 Released at 2009-10-31.
- Added a reload functionality to Log::Handler and
all output-modules.
0.60 Released at 2009-10-23.
- File.pm: "append" is now the default for option
"mode"
- Full release.
0.59_02 Released at 2009-10-17.
- Default for option newline is now 1.
0.59_01 Released at 2009-10-11.
- Kicked deprecated module Log::Handler::Simple.
- Kicked _close, _lock, _unlock in File.pm and moved the
functionalety into log() and close().
- Kicked deprecated option "reconnect" from DBI.pm.
- Added Log::Handler::Output::Sendmail.
0.58 Released at 2009-10-07.
- Forget to kick Devel::Backtrace from Log::Handler::Simple.
- Log::Handler::Simple will be kicked in the next release.
0.57 Released at 2009-10-06.
- Kicked UNIVERSAL::require.
- Kicked Devel::Backtrace.
0.56 Released at 2009-06-06.
- Just a full version.
0.55_01 Released at 2009-06-05.
- Oops... there was no _raise_error routine in
Log::Handler::Output::Screen.
- Fixed a bug in Handler.pm - the hash reference that were
passed to add() were changed (RT #46631).
0.54 Released at 2009-05-27.
- Just a full version.
0.53_01 Released at 2009-05-27.
- Fixed a bug in Log::Handler::Output::DBI - it was unable
to create a valid dsn for sqlite (RT #46407).
- Added option dbname
- Added option data_source
0.52 Released at 2009-05-24.
- No changes, just a full version.
0.51_01 Released at 2009-05-22.
- Added method set_level() to Handler.pm to change the log
level at runtime.
0.51 Released at 2009-03-07.
- Just a full release.
0.50_01 Released at 2009-03-07.
- Fixed a bug in the output DBI.pm - if the connection to
the database was lost then the message lost as well even
if a reconnect was successful.
- Added option prepare_message.
- Fixed message_pattern - the formatted messages was
overwritten if message_pattern was set.
- Option reconnect from Log::Handler::Output::DBI is
deprecated.
0.50 Released at 2008-11-27.
- Added the functionality to create a application logger.
New functions are create_logger and get_logger.
- Added option expect_caller, what is the opposite of
option filter_caller.
0.49 Released at 2008-11-16.
- Added patterns %U and %G (user, group).
- Fixed a bug in Socket.pm. If the server gone then
Log::Handler croaks even if die_on_errors is disabled.
- Fixed a bug in Output.pm. $log->error(0) logs nothing.
$log->error('foo', undef, 'bar') caused a warning.
0.48 Released at 2008-10-28.
- Fixed a bug in Email.pm - no error message if a email
couldn't be send.
- Added Email::Date to send the date with a email.
- EMAIL: if the key $message->{level} exists then the level is
used in the subject: "$level: $subject". The level can
passed with the option message_pattern.
0.47 Released at 2008-09-04.
- Add new config features. Now it's possilbe to add the
configuration for the outputs as a array reference.
- Add method log() to log with the level as first argument:
log($level=>$msg).
- Kicked Changes.pm. Not needed any more.
0.46 Released at 2008-07-28.
- Fixed Plugin::YAML. It was created as Plugin::Config::YAML.
- Did some code/example improvements.
0.45 Released at 2008-07-25.
- Kicked $self->{caller_level} and replaced it with
Log::Handler::CALLER_LEVEL. The reason is that if dump(),
die() or warn() was called then the patterns %p, %f, %c or
%s was wrong.
- Changed option filter to filter_message and added a new
option called filter_caller.
0.44 Released at 2008-06-04.
- Fixed set_pattern(). It dies if the key name is something like
'x-name' because $m->{x-name} is not valid.
- Changed pattern %R to %r.
0.43 Released at 2008-05-21.
- Fixed log() in DBI.pm and Socket.pm - only try to reconnect
if persistent + reconnect is set to true. Sorry :(
0.42 Released at 2008-05-21.
- Added $|=1 to Screen.pm.
- warn() is now a shortcut for warning().
- Add flush() to Handler.pm, Output.pm and File.pm.
- Added Perl version 5.6.1 to Build.PL (use warnings & utf8).
- Added a licence file.
- Fixed reconnect in DBI.pm.
- Fixed a lot of POD typos.
0.41 Released at 2008-05-09.
- Messages will be send to all outputs, even if a output is
not able to log a message. In version 0.40 the handler
stopped if a message couldn't be logged. That was bad.
- Did a lot code, POD and internal doc improvements.
0.40 Released at 2008-05-04.
- A full release - finally :-)
- Kicked all _and_trace and _and_die methods.
Replaced them with $log->die and $log->trace.
- Did some code and POD improvements.
0.39_17 Released at 2008-04-29.
- Kicked all _and_croak methods and carp() - to bloated.
- message_pattern and message_layout is now builded with eval.
- The patterns are not static any more. Changes at runtime are
possible with set_pattern().
- Fixed Log::Handler::Output::Email - forget to call sendmail()
if buffer is set to 0.
- Kicked option interval from Log::Handler::Output::Email.
- All log() methods of each output expects now a hash or a
hash reference with the message (message => $message).
Before this change it was possible to pass a hash reference
or a simple string: { message => $message } or just $message.
- Some other little improvements: POD, Code, Examples
0.39_16 Released at 2008-04-17.
- Kicked all _and_exit() methods - to bloated.
- Added Log::Handler::Pattern.
- Added Log::Handler::Output::Socket.
- Added option filter and alias to the handler.
- Added close() to Log::Handler::Output::File.
- Added connect() and disconnect() to Log::Handler::Output::DBI.
- Added connect() and disconnect() to Log::Handler::Output::Socket.
0.38_15 Released at 2008-03-06.
- The old style of Log::Handler version 0.38 is now implemented as
Log::Handler::Simple.
- POD improved; added Changes.pod, Examples.pod.
0.38_14 Released at 2008-02-17.
- Forget to delete some POD parts - sorry :/
0.38_13 Released at 2008-02-17.
- Kicked trace() and option "trace".
- Added trace methods for each level.
- Added croak, carp, die and warn methods for different levels.
- Log::Handler::Levels is now the base class for all level methods.
0.38_12 Released at 2008-02-16.
- Released with a lot of POD, code and example improvements.
0.38_11 Released at 2008-02-15.
- Changed option message_keys to message_pattern.
I hope that was the last change of this name :/
- Fixed POD typos and improved the documentation.
0.38_10 Released at 2008-02-13.
- Added Log::Handler::Output::Screen.
- Added option "priority" to the handler.
0.38_09 Released at 2008-02-09.
- Fixed t/100-config.t. Config::General was loaded, but it's not
in the prereq list. Kicked GLOBREF from the validate list for
config filename in Log::Handler::Config.
0.38_08 Released at 2008-02-08.
- Kicked eval { } from Log::Handler::Output::DBI.
- Missed documentation for dbi_params in Log::Handler::Output::DBI.
0.38_07 Released at 2008-02-08.
- Replaced options prefix and postfix with message_layout.
- Added %m as message to placeholders.
- Renamed option setinfo to message_keys.
- Added Log::Handler::Output::DBI.
- A lot of other code improvements.
- Moved the main logic from Log::Handler::Logger back to
Log::Handler.
- Renamed Log::Handler::Logger to Log::Handler::Output. This module
builds the output message and is just for internal usage.
- Renamed all output modules from Logger to Output.
- Patterns are not global any more. Now the patterns are stored
into the Log::Handler object.
- Changed option debug to debug_trace. The reason is that the
option debug can be used for output objects.
0.38_06 Released at 2008-01-20.
- POD improved and a lot of POD typos fixed.
- Fixed splitToTree argument for plugin Config::Properties.
- Different code improvements.
- Add option setinfo to Log::Handler::Logger.
- The message is now handled with a hash ref intern.
0.38_05 Released at 2008-01-19.
- Very annoyingly... wrong description for Log::Handler::Logger::Forward.
0.38_04 Released at 2008-01-19.
- Fixed test for parameter 'filename' in t/03handler.t.
- Fixed a lot of typos and improved the code.
- Added Log::Handler::Logger::Forward.
- Added Log::Handler::Logger::Email with Net::SMTP.
- Added fatal() to Log::Handler.
0.38_03 Released at 2008-01-14.
- Added Log::Handler::Config.pm.
- Added plugins for Config::General, Config::Properties and YAML.
- Fixed some POD typos.
0.38_02 Released at 2008-01-13.
- Fixed test for 'mode' in t/03handler.t.
- POD and intern documentation improved.
- Fixed example examples/trace.pl.
- Kicked method levels() from Log::Handler::Logger.
- Added the option trace. With this option it's possible
to deactivate the logging of trace messages to a logfile.
0.38_01 Released at 2008-01-13.
- Added Log::Handler::Logger and moved the main logger logic to it.
- Now it's possible to define more than one log file. Each log file
got it's own Log::Handler::Logger object.
- The simple call of "Log::Handler->new()" will not create a default
output object for *STDOUT any more, it just creates an empty Log::Handler object.
- To add log file the method add() should be used. The first log file can be
defined by new().
- The methods close(), set_prefix(), get_prefix are not available any more.
- The placeholder <--LEVEL--> for the prefix is changed to %L. In addition there
are different other placeholders available and it's possible to define a postfix.
- trace() will trace caller informations to all log files that are defined.
- Did a lot of other code changes.
0.38 Released at 2007-09-29.
- Kicked set_log_buffer() and get_buffer_log().
- Did some code improvements and split _print() into different routines.
- The option filename isn't mandatory any more. The default is *STDOUT.
0.37_01 Released at 2007-07-20.
- Added set_buffer_log() and get_buffer_log() to Log::Handler.
- Kicked now the would_log_* methods. Since 0.33 the is_* methods exists
as replacement.
0.37 Released at 2007-07-04.
- Added option rewrite_to_stderr.
- Replaced syswrite to print in _print().
0.36 Released at 2007-06-15.
- Now it's possible to set utf8 on the filehandle.
- Kicked CLOSE().
- Kicked File::Stat because CORE::stat() is much faster and I did some
other improvements. Now _print() is ~50% faster if reopen is used.
0.35 Released at 2007-06-05.
- Added method trace() to prints caller() to the log file.
- Did some code improvements and fixed POD typos.
0.34 Released at 2007-05-22.
- Changed the regex /.*\z/ to /.\z|^\z/ to append a newline if not
exists because /.*\z/ seems to be a regex bug.
0.33 Released at 2007-05-09.
- Added 13 is_* methods. They do the same as the would_log_* methods.
- Added close() as replacement for CLOSE(). CLOSE() exists in further
releases but is deprecated.
- Did some code improvements and fix some POD typos.
- Kicked IO::Handle from PREREQS and autoflush myself on the file handle.
0.32 Released at 2007-04-26.
I jumped from 0.15 to 0.32 because there exists brownfields on backpan.
Replaced my own routine to get caller() informations with Devel::Backtrace.
Added the option debugger_skip.
0.15 Released at 2007-04-25.
- Fixed typos in POD.
- Changed the way to activate the debugger. Now the debugger is activated
over the call of new().
0.14 Released at 2007-04-24.
- Fixed "use Log::Handler debug => ...".
0.13 Released at 2007-04-20.
- Added the availability to activate debugging with "Log::Handler debug => 1".
0.12 Released at 2007-04-15.
- Fixed DESTROY(). DESTROY() tries to unlock $self->{fh} in any case.
- Autoflush wasn't set if the option "filename" was set to STDOUT or
STDERR or a GLOBREF.
0.11 Released at 2007-04-10
- Add the methods set_prefix() and get_prefix(). Did some POD changes.
0.11_02 Released at 2007-04-04
- Add the alternative to set "nothing" as option for minlevel and
maxlevel.
0.11_01 Released at 2007-04-04
- I changed the log levels because they wasn't in the right order.
0 debug is now 7
1 info is now 6
2 notice is now 5
3 warning is now 4
4 error is now 3
5 crit is now 2
6 alert is now 1
7 emergency is now 0
8 nothing is still the same
If you set maxlevel and minlevel as strings in your code than
you don't need to change your code, but if you used numbers
than you must change it! BIG sorry to all users that have to
re-write code in this case.
- Thanks to betterworld for his tipps about the log levels! (thx pepe ;-))
0.10 Released at 2007-04-04
- Add the alternative to set STDOUT and STDERR as a string
with the option "filename".
0.09 Released at 2007-03-01.
- Fixed t/03handler.t. The test log file was in unix format
t/Log-Handler-Test-File.log, now it use File::Spec catfile().
- Forget to CLOSE() the log file in t/03handler.t and test fails
on Windows.
0.08 Released at 2007-02-25.
- Now it's possible to hand off GLOBREF to option filename.
There are some options that will be forced automatical:
- fileopen => 1
- filelock => 0
- reopen => 0
0.07 Released at 2007-03-13.
- Fixed t/03handler.t.
0.06 Released at 2007-03-11.
- Fixed a bad typo in SYNOPSIS of POD.
- Changed the description in NAME of POD.
0.05 Released at 2007-03-11.
- Fixed some typos in the documentation.
0.04 Released at 2007-03-09.
- Fixed code in new(). There was three typos.
0.03 Released at 2007-03-09.
- Fixed t/03handler.t.
- Added some points to the documentation.
- Add an example for die_on_errors.
- Add an example to call syslog methods.
- Different code changes.
- Fixed new(). Now it returns undef if open()
fails.
0.02 Released at 2007-02-05.
- Added eight new methods:
would_log_debug()
would_log_info()
would_log_notice(), would_log_note()
would_log_warning()
would_log_error(), would_log_err()
would_log_critical(), would_log_crit()
would_log_alert()
would_log_emergency(), would_log_emerg()
- Changed the POD.
0.01 Released at 2007-02-04.
x.xx Thanks to Larry Wall and all other Perl developers for Perl :-)
Log-Handler-0.90/LICENSE 0000640 0000000 0000000 00000002600 12235521676 013244 0 ustar root root Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
Log-Handler-0.90/examples/ 0000750 0000000 0000000 00000000000 12235521676 014056 5 ustar root root Log-Handler-0.90/examples/logger/ 0000750 0000000 0000000 00000000000 12235521676 015335 5 ustar root root Log-Handler-0.90/examples/logger/MyApp.pm 0000640 0000000 0000000 00000000340 12235521676 016717 0 ustar root root package MyApp;
use strict;
use warnings;
use Log::Handler myapp => 'LOG';
sub foo {
LOG->info('message from foo');
}
sub bar {
my $log = Log::Handler->get_logger('myapp');
$log->info('message from bar');
}
1;
Log-Handler-0.90/examples/logger/myapp.pl 0000640 0000000 0000000 00000001435 12235521676 017024 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you example how you can use C.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler myapp => 'LOG';
use lib '.';
use MyApp;
LOG->add(screen => {
newline => 1,
maxlevel => 'info',
message_layout => '%L - %m',
});
LOG->info('message from main');
MyApp->foo();
MyApp->bar();
Log-Handler-0.90/examples/reload/ 0000750 0000000 0000000 00000000000 12235521676 015324 5 ustar root root Log-Handler-0.90/examples/reload/logger1.conf 0000640 0000000 0000000 00000000635 12235521676 017540 0 ustar root root
alias = screen1
maxlevel = info
minlevel = emerg
priority = 2
message_layout = %L - screen1 %m
alias = screen2
maxlevel = info
minlevel = emerg
priority = 1
message_layout = %L - screen2 %m
alias = screen3
maxlevel = info
minlevel = emerg
priority = 3
message_layout = %L - screen3 %m
Log-Handler-0.90/examples/reload/reload.pl 0000640 0000000 0000000 00000000531 12235521676 017127 0 ustar root root #!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Log::Handler;
my $log = Log::Handler->new();
$log->config(config => "logger1.conf");
$log->warning("foo");
$log->info("foo");
print "--------------------------------------\n";
$log->reload(config => "logger2.conf") or die $log->errstr;
$log->warning("bar");
$log->info("bar");
Log-Handler-0.90/examples/reload/logger2.conf 0000640 0000000 0000000 00000000437 12235521676 017541 0 ustar root root
alias = screen1
maxlevel = warning
minlevel = emerg
priority = 2
message_layout = %T [%L] screen1 %m
alias = screen3
maxlevel = warning
minlevel = emerg
priority = 1
message_layout = %T [%L] screen3 %m
Log-Handler-0.90/examples/filter/ 0000750 0000000 0000000 00000000000 12235521676 015343 5 ustar root root Log-Handler-0.90/examples/filter/filter_message.pl 0000640 0000000 0000000 00000001437 12235521676 020677 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples how you can filter messages.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
filter_message => 'log this',
}
);
$log->info('log this');
$log->info('not that');
Log-Handler-0.90/examples/filter/filter_caller.pl 0000640 0000000 0000000 00000002356 12235521676 020516 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples how you can filter
messages from different callers.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
message_layout => '%L - (filter:foo) %m',
filter_caller => 'foo',
}
);
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
message_layout => '%L - (filter:bar) %m',
filter_caller => 'bar',
}
);
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
message_layout => '%L - (except:baz) %m',
except_caller => 'baz',
}
);
package foo;
$log->info('foo');
package bar;
$log->info('bar');
package baz;
$log->info('baz');
1;
Log-Handler-0.90/examples/filter/extended_filter.pl 0000640 0000000 0000000 00000002021 12235521676 021041 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples how you can filter messages.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
filter_message => {
match1 => 'log this',
match2 => qr/with that/,
match3 => '(?:or this|or that)',
condition => '(match1 && match2) || match3',
}
}
);
$log->info('log this with that');
$log->info('or this');
$log->info('or that');
$log->info('but not that');
Log-Handler-0.90/examples/layout/ 0000750 0000000 0000000 00000000000 12235521676 015373 5 ustar root root Log-Handler-0.90/examples/layout/layout.pl 0000640 0000000 0000000 00000002361 12235521676 017250 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples for all patterns.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->set_pattern('%x', 'x-name', 'x-value');
$log->add(
screen => {
message_layout =>
'level %L%N'.
'time %T%N'.
'date %D%N'.
'pid %P%N'.
'hostname %H%N'.
'caller %C%N'.
'package %p%N'.
'filename %f%N'.
'line %l%N'.
'subroutine %s%N'.
'progname %S%N'.
'runtime %r%N'.
'mtime %t%N'.
'message %m%N'.
'procent %%%N'.
'x-name %x%N',
}
);
$log->error('your message');
Log-Handler-0.90/examples/layout/pattern.pl 0000640 0000000 0000000 00000002036 12235521676 017407 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples for all patterns.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
use Data::Dumper;
my $log = Log::Handler->new();
$log->add(forward => {
forward_to => \&my_func,
message_pattern => [ qw/%T %L %H/ ],
message_layout => '',
maxlevel => 'info',
});
$log->info('a forwarded message');
# now you can access it
sub my_func {
my $msg = shift;
print "Timestamp: $msg->{time}\n";
print "Level: $msg->{level}\n";
print "Hostname: $msg->{hostname}\n";
print "Message: $msg->{message}\n";
}
Log-Handler-0.90/examples/layout/runtime.pl 0000640 0000000 0000000 00000001456 12235521676 017422 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you an example for the runtime patterns.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => 'debug',
message_layout => '%T %L %m runtime: %t, total runtime: %r%N',
}
);
while ( 1 ) {
$log->debug('--->');
sleep 1;
}
Log-Handler-0.90/examples/text-csv/ 0000750 0000000 0000000 00000000000 12235521676 015633 5 ustar root root Log-Handler-0.90/examples/text-csv/log-as-csv-string.pl 0000640 0000000 0000000 00000001050 12235521676 021444 0 ustar root root #!/usr/bin/perl
use strict;
use warnings;
use Log::Handler;
use Text::CSV;
my $log = Log::Handler->new();
my $csv = Text::CSV->new();
$log->add(
screen => {
maxlevel => 'info',
newline => 1,
message_layout => '%m',
message_pattern => '%T %L %P %t',
prepare_message => sub {
my $m = shift;
$csv->combine(@{$m}{qw/time level pid mtime message/});
$m->{message} = $csv->string;
},
}
);
$log->info('foo');
$log->info('bar');
$log->info('baz');
Log-Handler-0.90/examples/socket/ 0000750 0000000 0000000 00000000000 12235521676 015346 5 ustar root root Log-Handler-0.90/examples/socket/client.pl 0000640 0000000 0000000 00000002013 12235521676 017156 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This is a client example for Log::Handler::Output::Socket.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
socket => {
peeraddr => '127.0.0.1',
peerport => 44444,
newline => 1,
maxlevel => 'info',
die_on_errors => 0,
message_layout => '%T [%L] %U %H %S[%P] %m',
}
);
my $err = Log::Handler->new();
$err->add(screen => { newline => 1 });
while ( 1 ) {
$log->info('test')
or warn "unable to send message: ", $log->errstr;
sleep 1;
}
Log-Handler-0.90/examples/socket/server.pl 0000640 0000000 0000000 00000002133 12235521676 017211 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This is a server example for Log::Handler::Output::Socket.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use IO::Socket::INET;
use Log::Handler::Output::File;
my $sock = IO::Socket::INET->new(
LocalAddr => '127.0.0.1',
LocalPort => 44444,
Listen => 1,
) or die $!;
my $file = Log::Handler::Output::File->new(
filename => 'server.log',
mode => 'append',
fileopen => 1,
reopen => 1,
);
while ( 1 ) {
$file->log(message => "waiting for next connection\n");
while (my $request = $sock->accept) {
while (my $message = <$request>) {
$file->log(message => $message);
}
}
}
Log-Handler-0.90/examples/prepare/ 0000750 0000000 0000000 00000000000 12235521676 015514 5 ustar root root Log-Handler-0.90/examples/prepare/prepare.pl 0000640 0000000 0000000 00000002033 12235521676 017506 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
This script shows you examples for all patterns.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
use Data::Dumper;
my $log = Log::Handler->new();
$log->add(
screen => {
newline => 1,
message_layout => '%m (%t)',
message_pattern => [ qw/%T %L %H %m/ ],
prepare_message => \&format,
}
);
$log->error("foo bar baz");
$log->error("foo bar baz");
$log->error("foo bar baz");
sub format {
my $m = shift;
$m->{message} = sprintf('%-20s %-20s %-20s %s',
$m->{time}, $m->{level}, $m->{hostname}, $m->{message});
}
Log-Handler-0.90/examples/config/ 0000750 0000000 0000000 00000000000 12235521676 015323 5 ustar root root Log-Handler-0.90/examples/config/example.props 0000640 0000000 0000000 00000000201 12235521676 020035 0 ustar root root screen.maxlevel = debug
screen.minlevel = emerg
screen.newline = 1
screen.message_layout = %T %H[%P] [%L] Config::Properties %m
Log-Handler-0.90/examples/config/example.pl 0000640 0000000 0000000 00000001415 12235521676 017315 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
With this script you can test if the example configurations
works.
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->config(config => 'example.conf');
$log->config(config => 'example.yaml');
$log->config(config => 'example.props');
$log->info('info message');
Log-Handler-0.90/examples/config/example.conf 0000640 0000000 0000000 00000000207 12235521676 017625 0 ustar root root
maxlevel = debug
minlevel = emerg
newline = 1
message_layout = %T %H[%P] [%L] Config::General - %m
Log-Handler-0.90/examples/config/example.yaml 0000640 0000000 0000000 00000000150 12235521676 017637 0 ustar root root ---
screen:
maxlevel: debug
minlevel: emerg
newline: 1
message_layout: %T %H[%P] [%L] YAML - %m
Log-Handler-0.90/examples/category/ 0000750 0000000 0000000 00000000000 12235521676 015673 5 ustar root root Log-Handler-0.90/examples/category/category.pl 0000640 0000000 0000000 00000000520 12235521676 020043 0 ustar root root #!/usr/bin/perl
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => "info",
category => "Foo"
}
);
$log->info("Hello World!");
package Foo;
$log->info(__PACKAGE__);
package Foo::Bar;
$log->info(__PACKAGE__);
package Foooo;
$log->info(__PACKAGE__);
Log-Handler-0.90/examples/benchmark/ 0000750 0000000 0000000 00000000000 12442404265 016002 5 ustar root root Log-Handler-0.90/examples/benchmark/benchmark.pl 0000640 0000000 0000000 00000010350 12235521676 020277 0 ustar root root #!/usr/bin/perl
=head1 AUTHOR
Jonny Schulz
=head1 DESCRIPTION
Benchmarks... what else could I say...
=head1 POWERED BY
_ __ _____ _____ __ __ __ __ __
| |__| | | | \| |__|\ \/ /
| . | | | | | | | | > <
|____|__|_____|_____|__|\__|__|/__/\__\
=head1 COPYRIGHT
Copyright (C) 2007-2009 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
use strict;
use warnings;
use Log::Handler;
use Benchmark;
sub buffer { }
my $log1 = Log::Handler->new(); # simple pattern
my $log2 = Log::Handler->new(); # default pattern & suppressed
my $log3 = Log::Handler->new(); # complex pattern
my $log4 = Log::Handler->new(); # message pattern
my $log5 = Log::Handler->new(); # filtered caller
my $log6 = Log::Handler->new(); # filtered message
my $log7 = Log::Handler->new(); # categories
$log1->add(
forward => {
alias => 'simple pattern',
maxlevel => 'notice',
minlevel => 'notice',
forward_to => \&buffer,
message_layout => '%L - %m',
}
);
$log2->add(
forward => {
alias => 'default pattern & suppressed',
maxlevel => 'warning',
minlevel => 'warning',
forward_to => \&buffer,
}
);
$log3->add(
forward => {
alias => 'complex pattern',
maxlevel => 'info',
minlevel => 'info',
forward_to => \&buffer,
message_layout => '%T [%L] %H(%P) %m (%C)%N',
}
);
$log4->add(
forward => {
alias => 'message pattern',
maxlevel => 'error',
minlevel => 'error',
forward_to => \&buffer,
message_layout => '%m',
message_pattern => [qw/%T %L %P/],
}
);
$log5->add(
forward => {
alias => 'filtered caller',
maxlevel => 'emerg',
minlevel => 'emerg',
forward_to => \&buffer,
filter_caller => qr/^Foo\z/,
}
);
$log5->add(
forward => {
alias => 'filtered caller',
maxlevel => 'emerg',
minlevel => 'emerg',
forward_to => \&buffer,
filter_caller => qr/^Bar\z/,
}
);
$log5->add(
forward => {
alias => 'filtered caller',
maxlevel => 'emerg',
minlevel => 'emerg',
forward_to => \&buffer,
filter_caller => qr/^Baz\z/,
}
);
$log6->add(
forward => {
alias => 'filtered message',
maxlevel => 'alert',
minlevel => 'alert',
forward_to => \&buffer,
filter_message => qr/bar/,
}
);
$log6->add(
forward => {
alias => 'filtered message',
maxlevel => 'alert',
minlevel => 'alert',
forward_to => \&buffer,
filter_message => qr/bar/,
}
);
$log7->add(
forward => {
alias => 'categories',
maxlevel => 'alert',
minlevel => 'alert',
forward_to => \&buffer,
category => "Cat::Foo",
}
);
my $count = 100_000;
my $message = 'foo bar baz';
run("simple pattern output took", $count, sub { $log1->notice($message) } );
run("default pattern output took", $count, sub { $log2->warning($message) } );
run("complex pattern output took", $count, sub { $log3->info($message) } );
run("message pattern output took", $count, sub { $log4->error($message) } );
run("suppressed output took", $count, sub { $log2->debug($message) } );
run("filtered caller output took", $count, \&Foo::emerg );
run("suppressed caller output took", $count, \&Foo::Bar::emerg );
run("filtered messages output took", $count, sub { $log6->alert($message) } );
run("categorized messages output took", $count, \&Cat::Foo::Bar::alert );
run("suppressed categories output took", $count, \&Cat::Bar::Baz::alert );
sub run {
my ($desc, $count, $bench) = @_;
my $time = timeit($count, $bench);
print sprintf('%-30s', $desc), ' : ', timestr($time), "\n";
}
# Filter messages by caller
package Foo;
sub emerg { $log5->emerg($message) }
# Suppressed messages by caller
package Foo::Bar;
sub emerg { $log5->emerg($message) }
package Cat::Foo::Bar;
sub alert { $log7->alert($message) }
package Cat::Bar::Baz;
sub alert { $log7->alert($message) }
1;
Log-Handler-0.90/INSTALL 0000640 0000000 0000000 00000000521 12235521676 013270 0 ustar root root To install the module execute the following steps:
perl Makefile.PL
make
make test
"make test" do some tests. If you get error messages then
you shouldn't install the module. Otherwise your last step is:
make install
and have a lot of fun with Log::Handler.
Don't forget to take a look into the "examples" diretory. :-)
Log-Handler-0.90/META.json 0000644 0000000 0000000 00000006303 13702611501 013653 0 ustar root root {
"abstract" : "Log messages to several outputs.",
"author" : [
"Jonny Schulz"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.4224",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "Log-Handler",
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build" : "0.42"
}
},
"runtime" : {
"recommends" : {
"Config::General" : "0",
"Config::Properties" : "0",
"DBI" : "0",
"Email::Date" : "0",
"IO::Socket" : "0",
"Net::SMTP" : "0",
"YAML" : "0"
},
"requires" : {
"Carp" : "0",
"Data::Dumper" : "0",
"Fcntl" : "0",
"File::Spec" : "0",
"POSIX" : "0",
"Params::Validate" : "0",
"Sys::Hostname" : "0",
"Test::More" : "0",
"Time::HiRes" : "0",
"UNIVERSAL" : "0"
}
}
},
"provides" : {
"Log::Handler" : {
"file" : "lib/Log/Handler.pm",
"version" : "0.90"
},
"Log::Handler::Config" : {
"file" : "lib/Log/Handler/Config.pm",
"version" : "0.09"
},
"Log::Handler::Levels" : {
"file" : "lib/Log/Handler/Levels.pm",
"version" : "0.07"
},
"Log::Handler::Output" : {
"file" : "lib/Log/Handler/Output.pm",
"version" : "0.10"
},
"Log::Handler::Output::DBI" : {
"file" : "lib/Log/Handler/Output/DBI.pm",
"version" : "0.12"
},
"Log::Handler::Output::Email" : {
"file" : "lib/Log/Handler/Output/Email.pm",
"version" : "0.08"
},
"Log::Handler::Output::File" : {
"file" : "lib/Log/Handler/Output/File.pm",
"version" : "0.08"
},
"Log::Handler::Output::Forward" : {
"file" : "lib/Log/Handler/Output/Forward.pm",
"version" : "0.03"
},
"Log::Handler::Output::Screen" : {
"file" : "lib/Log/Handler/Output/Screen.pm",
"version" : "0.07"
},
"Log::Handler::Output::Sendmail" : {
"file" : "lib/Log/Handler/Output/Sendmail.pm",
"version" : "0.07"
},
"Log::Handler::Output::Socket" : {
"file" : "lib/Log/Handler/Output/Socket.pm",
"version" : "0.08"
},
"Log::Handler::Pattern" : {
"file" : "lib/Log/Handler/Pattern.pm",
"version" : "0.08"
},
"Log::Handler::Plugin::Config::General" : {
"file" : "lib/Log/Handler/Plugin/Config/General.pm",
"version" : "0.02"
},
"Log::Handler::Plugin::Config::Properties" : {
"file" : "lib/Log/Handler/Plugin/Config/Properties.pm",
"version" : "0.03"
},
"Log::Handler::Plugin::YAML" : {
"file" : "lib/Log/Handler/Plugin/YAML.pm",
"version" : "0.03"
}
},
"release_status" : "stable",
"resources" : {
"license" : [
"http://dev.perl.org/licenses/"
]
},
"version" : "0.90",
"x_serialization_backend" : "JSON::PP version 2.97001"
}
Log-Handler-0.90/MANIFEST.SKIP.bak 0000644 0000000 0000000 00000000411 13702611501 014656 0 ustar root root #!include_default
# Avoid configuration metadata file
^MYMETA\.
# Avoid Module::Build generated and utility files.
\bBuild$
\bBuild.bat$
\b_build
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
^MANIFEST\.SKIP
# Avoid archives of this distribution
\bLog-Handler-[\d\.\_]+
Log-Handler-0.90/MANIFEST 0000644 0000000 0000000 00000003503 13702611501 013362 0 ustar root root Build.PL
ChangeLog
debian/changelog
debian/compat
debian/control
debian/copyright
debian/dirs
debian/docs
debian/README.Debian
debian/rules
examples/benchmark/benchmark.pl
examples/category/category.pl
examples/config/example.conf
examples/config/example.pl
examples/config/example.props
examples/config/example.yaml
examples/filter/extended_filter.pl
examples/filter/filter_caller.pl
examples/filter/filter_message.pl
examples/layout/layout.pl
examples/layout/pattern.pl
examples/layout/runtime.pl
examples/logger/myapp.pl
examples/logger/MyApp.pm
examples/prepare/prepare.pl
examples/reload/logger1.conf
examples/reload/logger2.conf
examples/reload/reload.pl
examples/socket/client.pl
examples/socket/server.pl
examples/text-csv/log-as-csv-string.pl
INSTALL
lib/Log/Handler.pm
lib/Log/Handler/Config.pm
lib/Log/Handler/Examples.pod
lib/Log/Handler/Levels.pm
lib/Log/Handler/Output.pm
lib/Log/Handler/Output/DBI.pm
lib/Log/Handler/Output/Email.pm
lib/Log/Handler/Output/File.pm
lib/Log/Handler/Output/Forward.pm
lib/Log/Handler/Output/Screen.pm
lib/Log/Handler/Output/Sendmail.pm
lib/Log/Handler/Output/Socket.pm
lib/Log/Handler/Pattern.pm
lib/Log/Handler/Plugin/Config/General.pm
lib/Log/Handler/Plugin/Config/Properties.pm
lib/Log/Handler/Plugin/YAML.pm
LICENSE
Makefile.PL
MANIFEST This list of files
META.json
META.yml
perl-Log-Handler.spec
README
README.md
t/000-use.t
t/001-pod.t
t/002-pod-coverage.t
t/010-handler.t
t/011-handler-set-pattern.t
t/012-handler-message-pattern.t
t/013-handler-priority.t
t/014-handler-reload.t
t/015-handler-filter-caller.t
t/015-handler-filter-message.t
t/016-handler-alias.t
t/017-handler-special-levels.t
t/018-handler-logger.t
t/019-handler-setlevel.t
t/020-output-forward.t
t/030-output-file.t
t/040-output-email.t
t/045-output-sendmail.t
t/050-output-dbi.t
t/060-output-socket.t
t/090-test-undef.t
t/100-config.t
Log-Handler-0.90/README.md 0000640 0000000 0000000 00000000000 12433214366 013501 0 ustar root root Log-Handler-0.90/t/ 0000750 0000000 0000000 00000000000 13702611500 012465 5 ustar root root Log-Handler-0.90/t/010-handler.t 0000640 0000000 0000000 00000002616 12235521676 014611 0 ustar root root use strict;
use warnings;
use Test::More tests => 15;
use File::Spec;
use Log::Handler;
my $rand_num = int(rand(999999));
my $logfile = File::Spec->catfile('t', "Log-Handler-$rand_num.log");
my $log = Log::Handler->new();
$log->add(file => {
filename => [ 't', "Log-Handler-$rand_num.log" ],
fileopen => 0,
reopen => 0,
filelock => 0,
mode => 'excl',
autoflush => 1,
permissions => '0664',
timeformat => '',
message_layout => 'prefix [%L] %m',
maxlevel => 'debug',
minlevel => 'emergency',
die_on_errors => 1,
utf8 => 0,
debug_trace => 0,
debug_mode => 2,
debug_skip => 0,
});
ok(1, 'checking new');
ok(!-e $logfile, 'checking fileopen');
ok($log->is_debug, 'checking debug');
ok($log->is_info, 'checking info');
ok($log->is_notice, 'checking notice');
ok($log->is_warning, 'checking warning');
ok($log->is_warn, 'checking warn');
ok($log->is_error, 'checking error');
ok($log->is_err, 'checking err');
ok($log->is_critical, 'checking critical');
ok($log->is_crit, 'checking crit');
ok($log->is_alert, 'checking alert');
ok($log->is_emergency, 'checking emergency');
ok($log->is_emerg, 'checking emerg');
ok($log->is_fatal, 'checking fatal');
if (-e $logfile) {
unlink($logfile) or die $!;
}
Log-Handler-0.90/t/090-test-undef.t 0000640 0000000 0000000 00000000561 12235521676 015257 0 ustar root root use strict;
use warnings;
use Test::More tests => 4;
use Log::Handler;
local $SIG{__WARN__} = sub { die @_ };
sub forward { length($_[0]->{message}) }
my $log = Log::Handler->new();
ok(1, 'new');
$log->add(forward => { forward_to => \&forward });
ok(1, 'add');
ok($log->error('foo', undef, 'bar'), 'checking undef 1');
ok($log->error(undef), 'checking undef 2');
Log-Handler-0.90/t/012-handler-message-pattern.t 0000640 0000000 0000000 00000001767 12235521676 017716 0 ustar root root use strict;
use warnings;
use Test::More tests => 15;
use Log::Handler;
my $CHECKED = 0;
my %PATTERN = (
'%L' => 'level',
'%T' => 'time',
'%D' => 'date',
'%P' => 'pid',
'%H' => 'hostname',
'%C' => 'caller',
'%p' => 'package',
'%f' => 'filename',
'%l' => 'line',
'%s' => 'subroutine',
'%S' => 'progname',
'%r' => 'runtime',
'%t' => 'mtime',
'%m' => 'message',
);
my %PATTERN_REC = map { $_ => 0 } values %PATTERN;
sub check_struct {
my $m = shift;
foreach my $name (keys %$m) {
if (exists $PATTERN_REC{$name}) {
$PATTERN_REC{$name}++;
}
}
}
my $log = Log::Handler->new();
$log->add(
forward => {
forward_to => \&check_struct,
maxlevel => 'debug',
minlevel => 'debug',
message_layout => '',
message_pattern => [ keys %PATTERN ],
}
);
ok(1, 'new');
$log->debug('foo');
while ( my ($n, $v) = each %PATTERN_REC ) {
ok($v, "test pattern $n");
}
Log-Handler-0.90/t/100-config.t 0000640 0000000 0000000 00000004362 12235521676 014441 0 ustar root root use strict;
use warnings;
use Test::More tests => 14;
use Log::Handler;
my %config = (
file => {
default => {
timeformat => '%b %d %H:%M:%S',
mode => 'excl',
message_layout => '%T %H[%P] [%L] %S: %m',
debug_mode => 2,
fileopen => 0,
},
file1 => {
filename => 'foo',
maxlevel => 'info',
newline => 0,
priority => 1,
}
},
screen => [
{
alias => 'screen1',
dump => 1,
priority => 2,
maxlevel => 'info',
},
{
alias => 'screen2',
dump => 0,
newline => 0,
priority => 3,
maxlevel => 'info',
}
]
);
my $log = Log::Handler->new();
$log->config(config => \%config);
my %opts;
$opts{handler}{file1} = shift @{$log->{levels}->{INFO}};
$opts{handler}{screen1} = shift @{$log->{levels}->{INFO}};
$opts{handler}{screen2} = shift @{$log->{levels}->{INFO}};
$opts{output}{file1} = $log->output('file1');
$opts{output}{screen1} = $log->output('screen1');
$opts{output}{screen2} = $log->output('screen2');
my %cmp = (
output => {
file1 => {
filename => 'foo',
fileopen => 0,
},
screen1 => {
dump => 1,
},
screen2 => {
dump => 0,
}
},
handler => {
file1 => {
newline => 0,
timeformat => '%b %d %H:%M:%S',
message_layout => '%T %H[%P] [%L] %S: %m',
debug_mode => 2,
maxlevel => 6,
},
screen1 => {
priority => 2,
maxlevel => 6,
},
screen2 => {
newline => 0,
priority => 3,
maxlevel => 6,
}
}
);
foreach my $x (qw/handler output/) {
foreach my $y (qw/file1 screen1 screen2/) {
foreach my $k (keys %{$cmp{$x}{$y}}) {
my $cmp_val = $cmp{$x}{$y}{$k};
my $opt_val = defined $opts{$x}{$y}{$k} ? $opts{$x}{$y}{$k} : 'n/a';
ok($cmp_val eq $opt_val, "checking config $x:$y:$k ($cmp_val:$opt_val)");
}
}
}
Log-Handler-0.90/t/060-output-socket.t 0000640 0000000 0000000 00000003037 12235521676 016025 0 ustar root root use strict;
use warnings;
use Test::More;
BEGIN {
eval "use IO::Socket::INET;";
if ($@) {
plan skip_all => "No IO::Socket::INET installed";
exit(0);
}
if (!$ENV{LOG_HANDLER_SOCK_TEST}) {
plan skip_all => "Set \$ENV{LOG_HANDLER_SOCK_TEST} to 1 to enable this test";
exit(0);
}
};
use Log::Handler::Output::Socket;
use IO::Socket::INET;
eval {
$SIG{ALRM} = sub { die "STOP TEST" };
alarm 60;
};
my $sock = IO::Socket::INET->new(
LocalAddr => "127.0.0.1",
Proto => "tcp",
Listen => 1,
Timeout => 15
) or die $!;
my $port = $sock->sockport;
my $pid = fork;
if (!$pid) {
my $r = $sock->accept;
my $m = <$r> || "empty";
if ($m ne "test message from logger") {
die "something wents wrong ($m)";
}
$sock->close;
waitpid($pid, 0);
exit(0);
}
$sock->close;
sleep 1;
plan tests => 4;
ok(1, "fork");
my $log = Log::Handler::Output::Socket->new(
peeraddr => "127.0.0.1",
peerport => $port,
proto => "tcp",
timeout => 15,
persistent => 0,
reconnect => 0,
);
ok(1, "new");
$log->log(message => "test message from logger") or do {
ok(0, "testing log() - ".$log->errstr);
};
ok(1, "testing log()");
$log->reload(
{
peeraddr => "localhost",
peerport => $port,
proto => "tcp",
timeout => 15,
persistent => 0,
reconnect => 0,
}
);
ok($log->{sockopts}->{PeerAddr} eq "localhost", "checking reload ($log->{sockopts}->{PeerAddr})");
Log-Handler-0.90/t/030-output-file.t 0000640 0000000 0000000 00000002331 12235521676 015445 0 ustar root root use strict;
use warnings;
use Test::More tests => 6;
use File::Spec;
use Log::Handler::Output::File;
my $rand_num = int(rand(999999));
my $logfile = File::Spec->catfile('t', "Log-Handler-$rand_num.log");
my $log = Log::Handler::Output::File->new(
filename => [ 't', "Log-Handler-$rand_num.log" ],
permissions => '0664',
mode => 'append',
autoflush => 0,
fileopen => 0,
filelock => 0,
reopen => 0,
);
# write a string to the file
$log->log(message => "test\n") or die $!;
ok(1, "checking log()");
# checking if the file is readable
open(my $fh, '<', $logfile) or do {
ok(0, "open logfile ($logfile)");
exit(1);
};
ok(1, "open logfile ($logfile)");
my $line = <$fh>;
chomp($line);
close $fh;
ok($line =~ /^test\z/, "checking logfile ($line)");
if ( unlink($logfile) ) {
ok(1, "unlink logfile ($logfile)");
} else {
ok(0, "unlink logfile ($logfile)");
}
$log->reload(
{
filename => [ 't', "Log-Handler-$rand_num.log" ],
autoflush => 1,
fileopen => 0,
reopen => 0,
}
);
ok($log->{autoflush} == 1, "checking reload ($log->{autoflush})");
ok($log->{filename} =~ /$rand_num/, "checking reload ($log->{filename})");
Log-Handler-0.90/t/045-output-sendmail.t 0000640 0000000 0000000 00000001335 12235521676 016333 0 ustar root root use strict;
use warnings;
use Test::More tests => 4;
use Log::Handler::Output::Sendmail;
ok(1, "use ok");
$Log::Handler::Output::Sendmail::TEST = 1;
my $email = Log::Handler::Output::Sendmail->new(
from => 'bar@foo.example',
to => 'foo@bar.example',
subject => 'foo',
);
$email->log(message => "b");
$email->log(message => "a");
$email->log(message => "r");
ok($email->{subject} eq "foo", "checking subject ($email->{subject})");
ok($email->{message} eq "bar", "checking buffer ($email->{message})");
$email->reload(
{
from => 'bar@foo.example',
to => 'foo@bar.example',
subject => 'baz',
}
);
ok($email->{subject} eq "baz", "checking reload ($email->{subject})");
Log-Handler-0.90/t/001-pod.t 0000640 0000000 0000000 00000000272 12235521676 013752 0 ustar root root use strict;
use Test::More;
eval "use Test::Pod";
plan skip_all => "Test::Pod required for testing POD" if $@;
my @poddirs = qw( blib );
all_pod_files_ok( all_pod_files( @poddirs ) );
Log-Handler-0.90/t/013-handler-priority.t 0000640 0000000 0000000 00000002122 12235521676 016463 0 ustar root root use strict;
use warnings;
use Test::More tests => 7;
use Log::Handler;
my $PRIO_CHECK = 1;
sub prio_1 {
ok(1 == $PRIO_CHECK, "checking prio 1 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
sub prio_2 {
ok(2 == $PRIO_CHECK, "checking prio 2 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
sub prio_3 {
ok(3 == $PRIO_CHECK, "checking prio 3 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
sub prio_10 {
ok(4 == $PRIO_CHECK, "checking prio 10 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
sub prio_11 {
ok(5 == $PRIO_CHECK, "checking prio 11 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
sub prio_12 {
ok(6 == $PRIO_CHECK, "checking prio 12 ($PRIO_CHECK)");
$PRIO_CHECK++;
}
my $log = Log::Handler->new();
$log->add(forward => { forward_to => \&prio_3, priority => 3 });
$log->add(forward => { forward_to => \&prio_2, priority => 2 });
$log->add(forward => { forward_to => \&prio_1, priority => 1 });
$log->add(forward => { forward_to => \&prio_10 });
$log->add(forward => { forward_to => \&prio_11 });
$log->add(forward => { forward_to => \&prio_12 });
$log->error('foo');
ok($PRIO_CHECK == 7, 'all prios checked');
Log-Handler-0.90/t/000-use.t 0000640 0000000 0000000 00000000126 12235521676 013761 0 ustar root root use strict;
use warnings;
use Test::More tests => 1;
use Log::Handler;
ok(1, "use");
Log-Handler-0.90/t/019-handler-setlevel.t 0000640 0000000 0000000 00000002507 12235521676 016442 0 ustar root root use strict;
use warnings;
use Test::More tests => 2;
use Log::Handler;
my $MESSAGE;
sub test {
$MESSAGE++;
}
ok(1, "use");
my $log = Log::Handler->new();
$log->add(
forward => {
alias => "forward0",
forward_to => \&test,
minlevel => "emerg",
maxlevel => "error",
}
);
$log->add(
forward => {
alias => "forward1",
forward_to => \&test,
minlevel => "emerg",
maxlevel => "error",
}
);
$log->add(
forward => {
alias => "forward2",
forward_to => \&test,
minlevel => "emerg",
maxlevel => "error",
}
);
# should log nothing
$log->notice();
$log->set_level(
forward1 => {
minlevel => "emerg",
maxlevel => "debug",
}
);
# should only forward1 should log
$log->debug();
# disable logging for forward1 and
# enable it for forward0 and forward2
$log->set_level(
forward0 => {
minlevel => "emerg",
maxlevel => "debug",
}
);
$log->set_level(
forward1 => {
minlevel => "emerg",
maxlevel => "error",
}
);
$log->set_level(
forward2 => {
minlevel => "emerg",
maxlevel => "debug",
}
);
# should only log to forward0 and forward2
$log->debug();
ok($MESSAGE == 3, "check set_level($MESSAGE)");
Log-Handler-0.90/t/015-handler-filter-caller.t 0000640 0000000 0000000 00000001221 12235521676 017330 0 ustar root root use strict;
use warnings;
use Test::More tests => 3;
use Log::Handler;
my $CHECK = 0;
my $STRING = '';
ok(1, 'use');
my $log = Log::Handler->new();
ok(2, 'new');
$log->add(
forward => {
forward_to => \&check,
maxlevel => 6,
filter_caller => 'Foo::Bar',
message_layout => '%p',
newline => 0,
}
);
sub check {
my $m = shift;
if ($m->{message} eq 'Foo::Bar') {
$CHECK++;
}
}
Foo::Bar::baz();
Foo::Baz::baz();
ok($CHECK == 1, "checking filter_caller ($CHECK)");
package Foo::Bar;
sub baz {
$log->info();
}
package Foo::Baz;
sub baz {
$log->info();
}
1;
Log-Handler-0.90/t/050-output-dbi.t 0000640 0000000 0000000 00000003220 12235521676 015264 0 ustar root root use strict;
use warnings;
use Test::More;
BEGIN {
eval "use DBI;";
if ($@) {
plan skip_all => "No DBI installed";
exit(0);
}
};
use Log::Handler::Output::DBI;
plan tests => 8;
my ($ret, $log);
$log = Log::Handler::Output::DBI->new(
database => "dbname",
driver => "mysql",
user => "dbuser",
password => "dbpass",
host => "127.0.0.1",
port => 3306,
debug => 0,
table => "messages",
columns => "level message",
values => "%level %message",
persistent => 0,
);
ok(1, "new");
$ret = $log->{statement} eq "insert into messages (level,message) values (?,?)";
ok($ret, "checking statement");
#$ret = $log->{cstr}->[0] eq "dbi:mysql:database=dbname;host=127.0.0.1;port=3306";
$ret = $log->{cstr}->[0] eq "dbi:mysql:database=dbname;host=127.0.0.1;port=3306";
ok($ret, "checking cstr");
$ret = $log->{cstr}->[1] eq "dbuser";
ok($ret, "checking user");
$ret = $log->{cstr}->[2] eq "dbpass";
ok($ret, "checking password");
$ret = $log->{cstr}->[3]->{PrintError} == 0;
ok($ret, "checking argument PrintError");
$ret = $log->{cstr}->[3]->{AutoCommit} == 1;
ok($ret, "checking argument AutoCommit");
$log->reload(
{
database => "dbname",
driver => "mysql",
user => "dbuser",
password => "new password",
host => "127.0.0.1",
port => 3306,
debug => 0,
table => "messages",
columns => "level message",
values => "%level %message",
persistent => 0,
}
);
ok($log->{password} eq "new password", "checking reload ($log->{password})");
Log-Handler-0.90/t/011-handler-set-pattern.t 0000640 0000000 0000000 00000001714 12235521676 017054 0 ustar root root use strict;
use warnings;
use Test::More tests => 5;
use Log::Handler;
my $CHECKED;
sub check_struct {
$CHECKED = 1;
my $message = shift;
my $value = '';
if (ref($message) eq 'HASH') {
ok(1, "checking hashref");
$value = $message->{xname};
ok($value eq 'xvalue', "checking scalar ret value");
$value = $message->{yname};
ok($value eq 'yvalue', "checking code ret value");
} else {
ok(0, "checking hashref");
}
}
my $log = Log::Handler->new();
$log->set_pattern('%X', 'xname', 'xvalue');
$log->set_pattern('%Y', 'yname', sub { 'xxxxxx' });
$log->add(
forward => {
forward_to => \&check_struct,
maxlevel => 'debug',
minlevel => 'debug',
message_layout => '%m',
message_pattern => [ qw/%X %Y/ ],
}
);
ok(1, 'new');
$log->set_pattern('%Y', 'yname', sub { 'yvalue' });
$log->debug('foo');
ok($CHECKED, "call check_struct()");
Log-Handler-0.90/t/002-pod-coverage.t 0000640 0000000 0000000 00000002041 12235521676 015540 0 ustar root root use strict;
use warnings;
use Test::More;
eval "use Test::Pod::Coverage";
if ($@) {
plan skip_all => "Test::Pod::Coverage required for testing pod coverage";
exit 0;
}
my @modules = qw(
Log::Handler::Output
Log::Handler::Pattern
Log::Handler::Output
Log::Handler::Output::Forward
Log::Handler::Output::File
Log::Handler::Output::Sendmail
Log::Handler::Output::Socket
Log::Handler::Output::Screen
Log::Handler::Levels
Log::Handler
);
eval "use Config::Properties";
if (!$@) {
push @modules, "Log::Handler::Plugin::Config::Properties";
}
eval "Config::General";
if (!$@) {
push @modules, "Log::Handler::Plugin::Config::General";
}
eval "YAML";
if (!$@) {
push @modules, "Log::Handler::Plugin::YAML";
}
eval "DBI";
if (!$@) {
push @modules, "Log::Handler::Output::DBI";
}
eval "use Email::Date; use Net::SMTP";
if (!$@) {
push @modules, "Log::Handler::Output::Email";
}
plan tests => scalar @modules;
foreach my $mod (@modules) {
pod_coverage_ok($mod, "$mod is covered");
}
Log-Handler-0.90/t/017-handler-special-levels.t 0000640 0000000 0000000 00000002265 12235521676 017526 0 ustar root root use strict;
use warnings;
use Test::More tests => 23;
use Log::Handler;
my $MESSAGES = 13;
my $RECEIVED = 0;
my %LEVELS = (
DEBUG => 1,
INFO => 1,
NOTICE => 1,
WARNING => 2,
ERROR => 2,
CRITICAL => 2,
ALERT => 1,
EMERGENCY => 2,
FATAL => 1,
);
my @LEVELS = (qw/
debug
info
notice
warning
warn
error
err
critical
crit
alert
emergency
emerg
fatal
/);
sub forward {
my $m = shift;
if ($m->{message} =~ /([A-Z]+) foo/) {
my $level = $1;
if (exists $LEVELS{$level}) {
$LEVELS{$level}--;
}
$RECEIVED++;
}
}
my $log = Log::Handler->new();
$log->add(
forward => {
maxlevel => 'debug',
forward_to => \&forward,
message_layout => '%L %m',
}
);
# die
foreach my $level (@LEVELS) {
my $ul = uc($level);
eval { $log->die($level => 'foo') };
ok($@ =~ /foo/, "test die $level");
}
# count messages
ok($RECEIVED == $MESSAGES, "count messages ($RECEIVED:$MESSAGES)");
# got all messages?
while ( my ($level, $count) = each %LEVELS ) {
ok($count == 0, "test level $level ($count)");
}
Log-Handler-0.90/t/014-handler-reload.t 0000640 0000000 0000000 00000010351 12235521676 016054 0 ustar root root use strict;
use warnings;
use Test::More tests => 19;
use Log::Handler;
my %msg;
sub counter {
if (shift->{message} =~ /(INFO|WARN).+(unknown\d|forward\d)/) {
$msg{$2}{$1}++;
}
}
my $log = Log::Handler->new();
$log->config(
config => {
forward => [
{
alias => "forward1",
maxlevel => "info",
minlevel => "emerg",
priority => 2,
forward_to => \&counter,
message_layout => "%L - forward1 %m",
},
{
alias => "forward2",
maxlevel => "info",
minlevel => "emerg",
priority => 1,
forward_to => \&counter,
message_layout => "%L - forward2 %m",
},
{
alias => "forward3",
maxlevel => "info",
minlevel => "emerg",
priority => 3,
forward_to => \&counter,
message_layout => "%L - forward3 %m",
},
{
maxlevel => "info",
minlevel => "emerg",
priority => 3,
forward_to => \&counter,
message_layout => "%L - unknown1 %m",
},
],
},
);
$log->warning(1);
$log->info(1);
$log->reload(
config => {
forward => [
{
alias => "forward1",
maxlevel => "warning",
minlevel => "emerg",
priority => 2,
forward_to => \&counter,
message_layout => "%T [%L] forward1 %m",
},
{
alias => "forward3",
maxlevel => "warning",
minlevel => "emerg",
priority => 1,
forward_to => \&counter,
message_layout => "%T [%L] forward3 %m",
},
{
alias => "forward4",
maxlevel => "warning",
minlevel => "emerg",
priority => 1,
forward_to => \&counter,
message_layout => "%T [%L] forward4 %m",
},
{
alias => "forward5",
maxlevel => "warning",
minlevel => "emerg",
priority => 1,
forward_to => \&counter,
message_layout => "%T [%L] forward5 %m",
},
{
maxlevel => "warning",
minlevel => "emerg",
priority => 3,
forward_to => \&counter,
message_layout => "%L - unknown2 %m",
},
],
}
) or die $log->errstr;
ok(1, "reload");
$log->warning(1);
$log->info(1);
my $f1 = scalar keys %{$msg{forward1}};
my $f2 = scalar keys %{$msg{forward2}};
my $f3 = scalar keys %{$msg{forward3}};
my $f4 = scalar keys %{$msg{forward4}};
my $f5 = scalar keys %{$msg{forward5}};
ok($f1 == 2, "checking forward1 keys ($f1)");
ok($f2 == 2, "checking forward2 keys ($f2)");
ok($f3 == 2, "checking forward3 keys ($f3)");
ok($f4 == 1, "checking forward4 keys ($f4)");
ok($f5 == 1, "checking forward5 keys ($f5)");
ok($msg{forward1}{INFO} == 1, "checking forward1 INFO ($msg{forward1}{INFO})");
ok($msg{forward1}{WARN} == 2, "checking forward1 WARN ($msg{forward1}{WARN})");
ok($msg{forward2}{INFO} == 1, "checking forward2 INFO ($msg{forward2}{INFO})");
ok($msg{forward2}{WARN} == 1, "checking forward2 WARN ($msg{forward2}{WARN})");
ok($msg{forward3}{INFO} == 1, "checking forward3 INFO ($msg{forward3}{INFO})");
ok($msg{forward3}{WARN} == 2, "checking forward3 WARN ($msg{forward3}{WARN})");
ok($msg{forward4}{WARN} == 1, "checking forward3 WARN ($msg{forward4}{WARN})");
ok($msg{forward5}{WARN} == 1, "checking forward3 WARN ($msg{forward5}{WARN})");
ok($msg{forward5}{WARN} == 1, "checking forward3 WARN ($msg{forward5}{WARN})");
ok($msg{unknown1}{INFO} == 1, "checking unknown1 INFO ($msg{unknown1}{INFO})");
ok($msg{unknown1}{WARN} == 1, "checking unknown1 INFO ($msg{unknown1}{WARN})");
ok($msg{unknown2}{WARN} == 1, "checking unknown2 INFO ($msg{unknown1}{WARN})");
ok(!exists $msg{unknown2}{INFO}, "checking unknown2 INFO");
Log-Handler-0.90/t/015-handler-filter-message.t 0000640 0000000 0000000 00000003370 12235521676 017521 0 ustar root root use strict;
use warnings;
#use Test::More tests => 8;
use Test::More tests => 7;
use Log::Handler;
# Comment out "string 2" becaus ValidatePP.pm is unable to handle
# regexes on some perl versions! That is strange, but not a problem
# of Log::Handler.
my %STRING = (
'string 1' => 0,
# 'string 2' => 0,
'string 3' => 0,
'string 4' => 0,
'string 5' => 0,
);
ok(1, 'use');
my $log = Log::Handler->new();
ok(2, 'new');
$log->add(
forward => {
forward_to => \&check,
maxlevel => 6,
filter_message => 'string 1$',
}
);
#$log->add(
# forward => {
# forward_to => \&check,
# maxlevel => 6,
# filter_message => qr/STRING\s2$/i,
# }
#);
$log->add(
forward => {
forward_to => \&check,
maxlevel => 6,
filter_message => sub { shift->{message} =~ /string\s3$/ },
}
);
$log->add(
forward => {
forward_to => \&check,
maxlevel => 6,
filter_message => {
match1 => 'foo',
match2 => qr/bar/,
match3 => '(?:string\s4|string\s5)',
condition => '(!match1 && !match2) && match3',
}
}
);
ok(3, 'add');
sub check {
my $m = shift;
if ($m->{message} =~ /(string\s\d+)/) {
if (exists $STRING{$1}) {
$STRING{$1}++;
} else {
die "unexpected message $m->{message}";
}
}
}
$log->info('string 1');
#$log->info('string 2');
$log->info('string 3');
$log->info('string 4');
$log->info('string 5');
$log->info('string 1 foo');
#$log->info('string 2 foo');
$log->info('string 3 foo');
$log->info('string 4 foo');
$log->info('string 5 bar');
while ( my ($k, $v) = each %STRING ) {
ok($v == 1, "checking if $k match (hits:$v)");
}
Log-Handler-0.90/t/040-output-email.t 0000640 0000000 0000000 00000003074 12235521676 015623 0 ustar root root use strict;
use warnings;
use Test::More;
BEGIN {
eval "use Net::SMTP;";
if ($@) {
plan skip_all => "No Net::SMTP installed";
exit(0);
}
eval "use Email::Date;";
if ($@) {
plan skip_all => "No Email::Date installed";
exit(0);
}
};
plan tests => 4;
use Log::Handler::Output::Email;
$Log::Handler::Output::Email::TEST = 1;
my $log = Log::Handler::Output::Email->new(
host => [ "bloonix.de" ],
hello => "EHLO bloonix.de",
timeout => 60,
debug => 0,
from => 'jschulz.cpan@bloonix.de',
to => 'jschulz.cpan@bloonix.de',
subject => "Log::Handler::Output::Email test",
buffer => 20,
);
ok(1, "new");
# checking all log levels for would()
foreach my $i (1..10) {
$log->log(message => "test $i\n") or die $!;
}
ok(1, "checking log()");
# checking all lines
my $match_lines = 0;
my $all_lines = 0;
foreach my $line ( @{$log->{message_buffer}} ) {
++$all_lines;
next unless $line->{message} =~ /^test \d+$/;
++$match_lines;
}
if ($match_lines == 10) {
ok(1, "checking buffer ($all_lines:$match_lines)");
} else {
ok(0, "checking buffer ($all_lines:$match_lines)");
}
$log->reload(
{
host => [ "bloonix.de" ],
hello => "EHLO bloonix.de",
timeout => 60,
debug => 0,
from => 'jschulz.cpan@bloonix.de',
to => 'jschulz.cpan@bloonix.de',
subject => "Log::Handler::Output::Email test",
buffer => 100,
}
);
ok($log->{buffer} == 100, "checking reload ($log->{buffer})");
Log-Handler-0.90/t/016-handler-alias.t 0000640 0000000 0000000 00000000564 12235521676 015706 0 ustar root root use strict;
use warnings;
use Test::More tests => 1;
use Log::Handler;
my $ALIAS_CHECK = 0;
sub alias_check {
if ($_[0] =~ /foo/) {
$ALIAS_CHECK++
}
}
my $log = Log::Handler->new();
$log->add(
forward => {
forward_to => \&alias_check,
alias => 'test',
}
);
$log->output('test')->log('foo');
ok($ALIAS_CHECK, "checking alias");
Log-Handler-0.90/t/018-handler-logger.t 0000640 0000000 0000000 00000000772 12235521676 016077 0 ustar root root use strict;
use warnings;
use Test::More tests => 8;
use Log::Handler lhtest1 => 'LOG';
my $COUNT = 0;
ok(1, 'use');
foreach my $logger (qw/lhtest2 lhtest3/) {
Log::Handler->create_logger($logger);
ok(1, 'create logger');
my $log = Log::Handler->get_logger($logger);
$log->add(forward => {
forward_to => sub { $COUNT++ },
maxlevel => 'info',
});
ok(1, 'add screen output');
$log->info();
ok(1, 'log');
}
ok($COUNT == 2, "check counter ($COUNT)");
Log-Handler-0.90/t/020-output-forward.t 0000640 0000000 0000000 00000004653 12235521676 016202 0 ustar root root use strict;
use warnings;
use Test::More tests => 27;
use Log::Handler;
my @LINES = ();
my $RELOAD = 0;
sub save_lines {
my $foo = shift;
next unless $foo eq "foo";
push @LINES, $_[0]->{message};
}
sub reload {
$RELOAD++;
}
my $log = Log::Handler->new();
$log->add(
forward => {
alias => "forward",
forward_to => \&save_lines,
arguments => [ "foo" ],
maxlevel => "debug",
minlevel => "emergency",
message_layout => "prefix [%L] %m postfix",
}
);
ok(1, "add forward");
ok($log->is_debug, "checking is_debug");
ok($log->is_info, "checking is_info");
ok($log->is_notice, "checking is_notice");
ok($log->is_warning, "checking is_warning");
ok($log->is_error, "checking is_error");
ok($log->is_err, "checking is_err");
ok($log->is_critical, "checking is_critical");
ok($log->is_crit, "checking is_crit");
ok($log->is_alert, "checking is_alert");
ok($log->is_emergency, "checking is_emergency");
ok($log->is_emerg, "checking is_emerg");
ok($log->is_fatal, "checking is_fatal");
ok($log->debug("DEBUG"), "checking debug");
ok($log->info("INFO"), "checking info");
ok($log->notice("NOTICE"), "checking notice");
ok($log->warning("WARNING"), "checking warning");
ok($log->error("ERROR"), "checking error");
ok($log->err("ERROR"), "checking err");
ok($log->critical("CRITICAL"), "checking critical");
ok($log->crit("CRITICAL"), "checking crit");
ok($log->alert("ALERT"), "checking alert");
ok($log->emergency("EMERGENCY"), "checking emergency");
ok($log->emerg("EMERGENCY"), "checking emerg");
ok($log->fatal("FATAL"), "checking fatal");
# checking all lines that should be forwarded
my $match_lines = 0;
my $all_lines = 0;
foreach my $line ( @LINES ) {
++$all_lines;
next unless $line =~ /^prefix \[([A-Z]+)\] ([A-Z]+) postfix/;
next unless $1 eq $2;
++$match_lines;
}
if ($match_lines == 12) {
ok(1, "checking buffer ($all_lines:$match_lines)");
} else {
ok(0, "checking buffer ($all_lines:$match_lines)");
}
$log->reload(
config => {
forward => {
alias => "forward",
forward_to => \&reload,
maxlevel => "debug",
minlevel => "debug",
}
}
);
$log->notice("foo");
$log->info("bar");
$log->debug("baz");
ok($RELOAD == 1, "checking reload ($RELOAD)");
Log-Handler-0.90/META.yml 0000644 0000000 0000000 00000004217 13702611501 013505 0 ustar root root ---
abstract: 'Log messages to several outputs.'
author:
- 'Jonny Schulz'
build_requires: {}
configure_requires:
Module::Build: '0.42'
dynamic_config: 1
generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Log-Handler
provides:
Log::Handler:
file: lib/Log/Handler.pm
version: '0.90'
Log::Handler::Config:
file: lib/Log/Handler/Config.pm
version: '0.09'
Log::Handler::Levels:
file: lib/Log/Handler/Levels.pm
version: '0.07'
Log::Handler::Output:
file: lib/Log/Handler/Output.pm
version: '0.10'
Log::Handler::Output::DBI:
file: lib/Log/Handler/Output/DBI.pm
version: '0.12'
Log::Handler::Output::Email:
file: lib/Log/Handler/Output/Email.pm
version: '0.08'
Log::Handler::Output::File:
file: lib/Log/Handler/Output/File.pm
version: '0.08'
Log::Handler::Output::Forward:
file: lib/Log/Handler/Output/Forward.pm
version: '0.03'
Log::Handler::Output::Screen:
file: lib/Log/Handler/Output/Screen.pm
version: '0.07'
Log::Handler::Output::Sendmail:
file: lib/Log/Handler/Output/Sendmail.pm
version: '0.07'
Log::Handler::Output::Socket:
file: lib/Log/Handler/Output/Socket.pm
version: '0.08'
Log::Handler::Pattern:
file: lib/Log/Handler/Pattern.pm
version: '0.08'
Log::Handler::Plugin::Config::General:
file: lib/Log/Handler/Plugin/Config/General.pm
version: '0.02'
Log::Handler::Plugin::Config::Properties:
file: lib/Log/Handler/Plugin/Config/Properties.pm
version: '0.03'
Log::Handler::Plugin::YAML:
file: lib/Log/Handler/Plugin/YAML.pm
version: '0.03'
recommends:
Config::General: '0'
Config::Properties: '0'
DBI: '0'
Email::Date: '0'
IO::Socket: '0'
Net::SMTP: '0'
YAML: '0'
requires:
Carp: '0'
Data::Dumper: '0'
Fcntl: '0'
File::Spec: '0'
POSIX: '0'
Params::Validate: '0'
Sys::Hostname: '0'
Test::More: '0'
Time::HiRes: '0'
UNIVERSAL: '0'
resources:
license: http://dev.perl.org/licenses/
version: '0.90'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Log-Handler-0.90/Build.PL 0000640 0000000 0000000 00000001727 12235521676 013544 0 ustar root root use strict;
use warnings;
use Module::Build;
my $build = Module::Build->new(
create_readme => 1,
create_makefile_pl => "traditional",
license => "perl",
module_name => "Log::Handler",
dist_author => "Jonny Schulz",
sign => 0,
recommends => {
"Config::General" => 0,
"Config::Properties" => 0,
"DBI" => 0,
"IO::Socket" => 0,
"Net::SMTP" => 0,
"Email::Date" => 0,
"YAML" => 0,
},
requires => {
"Carp" => 0,
"Data::Dumper" => 0,
"Fcntl" => 0,
"File::Spec" => 0,
"Params::Validate" => 0,
"POSIX" => 0,
"Test::More" => 0,
"Time::HiRes" => 0,
"Sys::Hostname" => 0,
"UNIVERSAL" => 0,
},
);
$build->create_build_script;
Log-Handler-0.90/debian/ 0000750 0000000 0000000 00000000000 12422402505 013445 5 ustar root root Log-Handler-0.90/debian/rules 0000750 0000000 0000000 00000000127 12377565454 014553 0 ustar root root #!/usr/bin/make -f
%:
dh $@
override_dh_auto_test:
AUTOMATED_TESTING=0 dh_auto_test
Log-Handler-0.90/debian/README.Debian 0000640 0000000 0000000 00000000241 12376707077 015530 0 ustar root root This software is copyright protected! The author is
Jonny Schulz
Copyright:
Copyright (C) 2010-2014 by Jonny Schulz. All rights reserved.
Log-Handler-0.90/debian/compat 0000640 0000000 0000000 00000000002 12377565336 014671 0 ustar root root 7
Log-Handler-0.90/debian/docs 0000640 0000000 0000000 00000000032 12377565441 014336 0 ustar root root ChangeLog
INSTALL
LICENSE
Log-Handler-0.90/debian/dirs 0000640 0000000 0000000 00000000000 12377565434 014344 0 ustar root root Log-Handler-0.90/debian/copyright 0000640 0000000 0000000 00000000225 12376735463 015424 0 ustar root root This software is copyright protected! The author is
Jonny Schulz
Copyright (C) 2010-2014 by Jonny Schulz. All rights reserved.
Log-Handler-0.90/debian/control 0000640 0000000 0000000 00000001241 12400220040 015033 0 ustar root root Source: liblog-handler-perl
Section: perl
Priority: optional
Build-Depends: debhelper (>= 8),
perl
Build-Depends-Indep: libdbi-perl,
libemail-date-perl,
libmro-compat-perl,
libparams-validate-perl,
libtest-pod-coverage-perl,
libtest-pod-perl
Maintainer: Jonny Schulz
Standards-Version: 3.9.3
Homepage: http://www.bloonix.de/
Package: liblog-handler-perl
Architecture: all
Depends: ${perl:Depends},
liblog-handler-perl
Suggests: libconfig-general-perl,
libdbi-perl,
libemail-date-perl,
libmro-compat-perl,
libyaml-perl
Description: Log messages to several outputs.
Log::Handler is an easy-to-use Perl module for logging, debugging, and tracing.
Log-Handler-0.90/debian/changelog 0000640 0000000 0000000 00000000733 12422402453 015325 0 ustar root root liblog-handler-perl (0.84-1) unstable; urgency=low
* Fixed some version conflicts.
-- Jonny Schulz Fri, 24 Oct 2014 07:00:00 +0200
liblog-handler-perl (0.83-1) unstable; urgency=low
* Added method set_default_param.
-- Jonny Schulz Thu, 23 Oct 2014 22:00:00 +0200
liblog-handler-perl (0.82-1) unstable; urgency=low
* Initial self-created debian release.
-- Jonny Schulz Mon, 25 Aug 2014 15:00:00 +0200
Log-Handler-0.90/perl-Log-Handler.spec 0000640 0000000 0000000 00000002523 13702611114 016136 0 ustar root root Summary: Log Handler
Name: perl-Log-Handler
Version: 0.90
Release: 1%{dist}
License: GPL+ or Artistic
Group: Development/Libraries
Distribution: RHEL and CentOS
Packager: Jonny Schulz
Vendor: Bloonix
BuildArch: noarch
BuildRoot: %{_tmppath}/Log-Handler-%{version}-%{release}-root
Source0: http://search.cpan.org/CPAN/authors/id/B/BL/BLOONIX/Log-Handler-%{version}.tar.gz
Provides: perl(Log::Handler)
Requires: perl(Params::Validate)
AutoReqProv: no
%description
Log::Handler is an easy-to-use Perl module for logging, debugging, and tracing.
%prep
%setup -q -n Log-Handler-%{version}
%build
%{__perl} Build.PL installdirs=vendor
%{__perl} Build
%install
%{__perl} Build install destdir=%{buildroot} create_packlist=0
find %{buildroot} -name .packlist -exec %{__rm} {} \;
find %{buildroot} -type f -name .packlist -exec rm -f {} ';'
find %{buildroot} -type f -name '*.bs' -a -size 0 -exec rm -f {} ';'
%{_fixperms} %{buildroot}/*
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%doc ChangeLog INSTALL LICENSE
%{perl_vendorlib}/*
%{_mandir}/man3/*
%changelog
* Fri Oct 24 2014 Jonny Schulz - 0.84-1
- Fixed some version conflicts.
* Thu Oct 23 2014 Jonny Schulz - 0.83-1
- Added method set_default_param.
* Mon Aug 25 2014 Jonny Schulz - 0.82-1
- Initial self-created RPM release.
Log-Handler-0.90/lib/ 0000750 0000000 0000000 00000000000 12235521676 013006 5 ustar root root Log-Handler-0.90/lib/Log/ 0000750 0000000 0000000 00000000000 13702611105 013512 5 ustar root root Log-Handler-0.90/lib/Log/Handler.pm 0000640 0000000 0000000 00000151175 13702611105 015440 0 ustar root root =head1 NAME
Log::Handler - Log messages to several outputs.
=head1 SYNOPSIS
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
file => {
filename => "file.log",
maxlevel => "debug",
minlevel => "warning",
}
);
$log->warning("message");
Or
use Log::Handler;
my $log = Log::Handler->new(
screen => {
log_to => "STDOUT",
maxlevel => "debug",
minlevel => "debug",
message_layout => "%T [%L] %m (%C)",
},
screen => {
log_to => "STDOUT",
maxlevel => "info",
minlevel => "notice",
},
screen => {
log_to => "STDERR",
maxlevel => "warning",
minlevel => "emergency",
},
);
Or
use Log::Handler;
my $log = Log::Handler->new();
$log->config( config => "logger.conf" );
# and maybe later
$log->reload( config => "logger.conf" );
Or
# create a application wide logger
package MyApp;
use Log::Handler;
my $log = Log::Handler->create_logger("myapp");
$log->add(screen => { maxlevel => "info" });
$log->info("info message");
# get logger with get_logger()
package MyApp::Admin;
use Log::Handler;
my $log = Log::Handler->get_logger("myapp");
$log->info("info message from MyApp::Admin");
=head1 DESCRIPTION
The C is a object oriented handler for logging, tracing and
debugging. It is very easy to use and provides a simple interface for
multiple output objects with lots of configuration parameters. You can
easily filter the amount of logged information on a per-output base,
define priorities, create patterns to format the messages and reload
the complete logging machine.
See the documentation for details.
=head1 IMPORTANT NOTES
Note that the default for option C is now set to TRUE and newlines
will be appended automatically to each message if no newline exists.
A long time I thought about this serious change and have come to
the decision to change it.
The default for option C from Log::Handler::Output::File is now
C and not C anymore.
The methods C and C are new since version 0.62.
I tested it with Screen.pm, File.pm and DBI.pm and it runs fine.
If you find bugs then open a bug report please :-)
=head1 LOG LEVELS
There are eigth levels available:
7 debug
6 info
5 notice
4 warning, warn
3 error, err
2 critical, crit
1 alert
0 emergency, emerg
C is the highest and C is the lowest level.
Level C is the highest level because it basically says to log
every peep.
=head1 LOG LEVEL METHODS
=head2 Level methods
=over 4
=item B
=item B
=item B
=item B, B
=item B, B
=item B, B
=item B
=item B, B
=back
The call of a log level method is very simple:
$log->info("Hello World! How are you?");
Or maybe:
$log->info("Hello World!", "How are you?");
Both calls would log - if level INFO is active:
Feb 01 12:56:31 [INFO] Hello World! How are you?
=head2 is_* methods
=over 4
=item B
=item B
=item B
=item B, B
=item B, B
=item B, B
=item B
=item B, B
=back
These twelve methods could be very useful if you want to kwow if the current
level would log the message. All methods returns TRUE if the current set
of C and C would log the message and FALSE if not.
=head1 SPECIAL LOG METHODS
=over 4
=item B, B
=item B
=item B
=item B
=item B
=back
For a full list take a look into the documentation of L.
=head1 METHODS
=head2 new()
Call C to create a new log handler object.
my $log = Log::Handler->new();
=head2 add()
Call C to add a new output object.
The method expects 2 parts of options; the options for the handler and
the options for the output module you want to use. The output modules got it's own
documentation for all options.
Example:
use Log::Handler;
my $log = Log::Handler->new();
$log->add(
# Add "file output"
file => {
# handler options (see Log::Handler)
timeformat => "%Y/%m/%d %H:%M:%S",
message_layout => "%T [%L] %S: %m",
maxlevel => "debug",
minlevel => "emergency",
die_on_errors => 1,
debug_trace => 0,
debug_mode => 2,
debug_skip => 0,
# file options (see Log::Handler::Output::File)
filename => "file.log",
filelock => 1,
fileopen => 1,
reopen => 1,
autoflush => 1,
permissions => "0660",
utf8 => 1,
}
);
Take a look to L for more examples.
The following options are possible for the handler:
=over 4
=item B and B
With these options it's possible to set the log levels for your program.
Example:
maxlevel => "error"
minlevel => "emergency"
# or
maxlevel => "err"
minlevel => "emerg"
# or
maxlevel => 3
minlevel => 0
It's possible to set the log level as string or as number. The default setting
for C is C and the default setting for C is
C.
Example: If C is set to C and C to C
then the levels C, C, C, C and C
would be logged.
You can set both to 8 or C if you want to disable the logging machine.
=item B
The option C is used to set the format for the placeholder C<%T>.
The string is converted with C. The default format is set to
S<"%b %d %H:%M:%S"> and looks like
Feb 01 12:56:31
If you would set the format to S<"%Y/%m/%d %H:%M:%S"> it would looks like
2007/02/01 12:56:31
=item B
This options works like C. You can set a format that is used for
the placeholder C<%D>. It's just useful if you want to split the date and time:
$log->add(file => {
filename => "file.log",
dateformat => "%Y-%m-%d",
timeformat => "%H:%M:%S",
message_layout => "%D %T %L %m",
});
$log->error("an error here");
This looks like
2007-02-01 12:56:31 ERROR an error here
This option is not used by default.
=item B
C is a very helpful option. It let the logger appends a newline to
the message if a newline doesn't exist.
0 - do nothing
1 - append a newline if not exist (default)
Example:
$log->add(
screen => {
newline => 1,
maxlevel => "info",
}
);
$log->info("message\n");
$log->info("message");
In both cases the message would be logged with a newline at the end.
=item B
With this option it's possible to create your own message layout with different
placeholders in C style. The available placeholders are:
%L Log level
%T Time or full timestamp (option timeformat)
%D Date (option dateformat)
%P PID
%H Hostname
%U User name
%G Group name
%N Newline
%S Program name
%C Caller - filename and line number
%p Caller - package name
%f Caller - file name
%l Caller - line number
%s Caller - subroutine name
%r Runtime in seconds since program start
%t Time measurement - replaced with the time since the last call of $log->$level
%m Message
%% Percent
The default message layout is set to S<"%T [%L] %m">.
As example the following code
$log->alert("foo bar");
would log
Feb 01 12:56:31 [ALERT] foo bar
If you set C to
message_layout => "%T foo %L bar %m (%C)"
and call
$log->info("baz");
then it would log
Feb 01 12:56:31 foo INFO bar baz (script.pl, line 40)
Traces will be appended after the complete message.
You can create your own placeholders with the method C.
=item B
This option is just useful if you want to forward messages to output
modules that needs the parts of a message as a hash reference - as
example L, L
or L.
The option expects a list of placeholders:
# as a array reference
message_pattern => [ qw/%T %L %H %m/ ]
# or as a string
message_pattern => "%T %L %H %m"
The patterns will be replaced with real names as hash keys.
%L level
%T time
%D date
%P pid
%H hostname
%U user
%G group
%N newline
%r runtime
%C caller
%p package
%f filename
%l line
%s subroutine
%S progname
%t mtime
%m message
Here a full code example:
use Log::Handler;
my $log = Log::Handler->new();
$log->add(forward => {
forward_to => \&my_func,
message_pattern => [ qw/%T %L %H %m/ ],
message_layout => "%m",
maxlevel => "info",
});
$log->info("a forwarded message");
# now you can access it
sub my_func {
my $msg = shift;
print "Timestamp: $msg->{time}\n";
print "Level: $msg->{level}\n";
print "Hostname: $msg->{hostname}\n";
print "Message: $msg->{message}\n";
}
=item B
C is useful if you want to do something with the message before
it will be logged... maybe you want to create your own layout because message_layout
doesn't meet your claim.
$log->add(
screen => {
newline => 1,
message_layout => "%m (%t)",
message_pattern => [ qw/%T %L %H %m/ ],
prepare_message => \&format,
}
);
$log->error("foo");
$log->error("bar");
$log->error("baz");
sub format {
my $m = shift;
$m->{message} = sprintf("%-20s %-20s %-20s %s",
$m->{time}, $m->{level}, $m->{hostname}, $m->{message});
}
The output looks like
Mar 08 15:14:20 ERROR h1434036 foo (0.039694)
Mar 08 15:14:20 ERROR h1434036 bar (0.000510)
Mar 08 15:14:20 ERROR h1434036 baz (0.000274)
=item B
With this option you can set the priority of your output objects. This means
that messages will be logged at first to the outputs with a higher priority.
If this option is not set then the default priority begins with 10 and will be
increased +1 with each output. Example:
We add a output with no priority
$log->add(file => { filename => "file1.log" });
This output gets the priority of 10. Now we add another output
$log->add(file => { filename => "file2.log" });
This output gets the priority of 11... and so on.
Messages would be logged at first to the output with the priority of 10 and then
to the output with the priority of 11. Now you can add another output and set the
priority to 1.
$log->add(screen => { dump => 1, priority => 1 });
Messages would be logged now at first to the screen.
=item B
Set C to 0 if you don't want that the handler dies on failed
write operations.
0 - to disable it
1 - to enable it
If you set C to 0 then you have to control it yourself.
$log->info("info message") or die $log->errstr();
# or Log::Handler->errstr()
# or Log::Handler::errstr()
# or $Log::Handler::ERRSTR
=item B
This option is set to 1 by default.
Take a look to the description of the method C for more
information about this option.
=item B
With this option it's possible to set a filter. If the filter is set then
only messages will be logged that match the filter. You can pass a regexp,
a code reference or a simple string. Example:
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => qr/log this/,
# or
# filter_message => "log this",
# filter_message => '^log only this$',
});
$log->info("log this");
$log->info("but not that");
If you pass your own code then you have to check the message yourself.
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => \&my_filter
});
# return TRUE if you want to log the message, FALSE if not
sub my_filter {
my $msg = shift;
$msg->{message} =~ /your filter/;
}
It's also possible to define a simple condition with matches. Just pass a
hash reference with the options C and C. Example:
$log->add(file => {
filename => "file.log",
maxlevel => 6,
filter_message => {
match1 => "log this",
match2 => qr/with that/,
match3 => "(?:or this|or that)",
condition => "(match1 && match2) || match3",
}
});
NOTE that re-eval in regexes is not valid! Something like
match1 => '(?{unlink("file.txt")})'
would cause an error!
=item B
This is the opposite of option C, but it's only possible to set
a simple string or regular expression.
$log->add(file => {
filename => "file.log",
maxlevel => 6,
skip => '^do not log this.+$'
});
=item B
The parameter C works like C but is much easier to configure.
You can set a comma separated list of modules. As example if you would set the category to
category => "MyApp::User"
then all messages of MyApp::User and the submodules would be logged.
Example:
my $log = Log::Handler->new();
$log->add(
screen => {
maxlevel => "info",
category => "MyApp::User, MyApp::Session"
}
);
package MyApp;
$log->info(__PACKAGE__);
package MyApp::Products;
$log->info(__PACKAGE__);
package MyApp::User;
$log->info(__PACKAGE__);
package MyApp::Users;
$log->info(__PACKAGE__);
package MyApp::User::Settings;
$log->info(__PACKAGE__);
package MyApp::Session;
$log->info(__PACKAGE__);
package MyApp::Session::Settings;
$log->info(__PACKAGE__);
The messages of C and C would not be logged.
The usage of categories is much faster than to filter by caller.
=item B
You can use this option to set a package name. Only messages from this
packages will be logged.
Example:
my $log = Log::Handler->new();
$log->add(screen => {
maxlevel => "info",
filter_caller => qr/^Foo::Bar\z/,
# or
# filter_caller => "^Foo::Bar\z",
});
package Foo::Bar;
$log->info("log this");
package Foo::Baz;
$log->info("but not that");
1;
This would only log the message from the package C.
=item B
This option is just the opposite of C.
If you want to log messages from all callers but C:
except_caller => qr/^Foo::Bar\z/
=item B
You can set an alias if you want to get the output object later. Example:
my $log = Log::Handler->new();
$log->add(screen => {
maxlevel => 7,
alias => "screen-out",
});
my $screen = $log->output("screen-out");
$screen->log(message => "foo");
# or in one step
$log->output("screen-out")->log(message => "foo");
=item B
You can activate a debugger that writes C information about each
active log level. The debugger is logging all defined values except C
and C. Set C to 1 to activate the debugger.
The debugger is set to 0 by default.
=item B
There are two debug modes: line(1) and block(2) mode. The default mode is 1.
The line mode looks like this:
use strict;
use warnings;
use Log::Handler;
my $log = Log::Handler->new()
$log->add(file => {
filename => "*STDOUT",
maxlevel => "debug",
debug_trace => 1,
debug_mode => 1
});
sub test1 { $log->warning() }
sub test2 { &test1; }
&test2;
Output:
Apr 26 12:54:11 [WARNING]
CALL(4): package(main) filename(./trace.pl) line(15) subroutine(main::test2) hasargs(0)
CALL(3): package(main) filename(./trace.pl) line(13) subroutine(main::test1) hasargs(0)
CALL(2): package(main) filename(./trace.pl) line(12) subroutine(Log::Handler::__ANON__) hasargs(1)
CALL(1): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(713) subroutine(Log::Handler::_write) hasargs(1)
CALL(0): package(Log::Handler) filename(/usr/local/share/perl/5.8.8/Log/Handler.pm) line(1022) subroutine(Devel::Backtrace::new) hasargs(1) wantarray(0)
The same code example but the debugger in block mode would looks like this:
debug_mode => 2
Output:
Apr 26 12:52:17 [DEBUG]
CALL(4):
package main
filename ./trace.pl
line 15
subroutine main::test2
hasargs 0
CALL(3):
package main
filename ./trace.pl
line 13
subroutine main::test1
hasargs 0
CALL(2):
package main
filename ./trace.pl
line 12
subroutine Log::Handler::__ANON__
hasargs 1
CALL(1):
package Log::Handler
filename /usr/local/share/perl/5.8.8/Log/Handler.pm
line 681
subroutine Log::Handler::_write
hasargs 1
CALL(0):
package Log::Handler
filename /usr/local/share/perl/5.8.8/Log/Handler.pm
line 990
subroutine Devel::Backtrace::new
hasargs 1
wantarray 0
=item B
This option let skip the C information the count of C.
=back
=head2 output()
Call C