- or download this
#!/bin/perl
use Log::Painless; # sends warnings, info, and exceptions to m
+ain.log
...
info "Logging begun";
warn "Hello, there!"; #behaves like warn, but logs warning as
+well.
die "Program done."; #behaves like die, but logs exception as
+ well.
- or download this
use Log::Painless { file => 'myscript.log', level => 'debug' }
+;
- or download this
use Log::Painless { level => 'debug' };
...
debug leave; # as enter, above, but "Left subroutine"
}
test_log();
- or download this
info 'Starting to connect to data source: '.$dsn;
- or download this
eval {
$dbh = DBI->connect('dbi:SQLite2:dbname=test.db','',''
+) or
...
warn "Falling back to CSV file..."
# do stuff.
}
- or download this
2006-03-14T13:21:32 4508 E (myscript.pl/11):Can't connect!
2006-03-14T13:21:32 4508 I Caught exception [Can't connect!] 1
+ evals deep in main
2006-03-14T13:21:32 4508 W (myscript.pl/16):Falling back to CS
+V file...
- or download this
sub test_sub {
trace enter;
# .. some stuff
}
- or download this
2006-03-14T13:21:33 4509 T Entered subroutine main::test_sub
- or download this
sub test_sub {
# .. some stuff
trace leave;
}
- or download this
2006-03-14T13:21:35 4509 T Left subroutine main::test_sub
- or download this
use Log::Painless { file => 'messages.log' };
- or download this
use Log::Painless { level => 'debug' }; # only trace will be s
+upressed
- or download this
use Log::Painless { shortcuts => [ 'caught' ] }; # only import
+ caught()
- or download this
Log::Painless->divert('debug' => 'debug.log');
- or download this
Log::Painless->duplicate('debug' => *STDERR);
- or download this
Log::Painless->divert('debug' => 'debug.log');
Log::Painless->duplicate('debug' => *STDERR);
- or download this
use Log::Painless;
{
...
$old_warn->(@_);
};
}
- or download this
Date-Time PID Type-Char Message
With default format settings, this results in something like:
- or download this
2006-03-14T14:22:32 4856 E (testlog.pl/10):the death
- or download this
use Log::Painless {
lineformat => sub { my $m = shift; $m=~s/^(.*?) \d+/$1
+/; return $m },
};
- or download this
package Log::Painless;
...
1;