D
Dan
I want to set up Log:ispatch with two outputs... "file" and "email".
I'd like to use a callback function to do custom formatting of the
message based on whether the output is going to a logfile or email.
I.E. a one line entry if sent to logfile and a verbose description,
possibly including html, hyperlinks, etc if sent by email.
I figured since the log method supports sending arbitrary named pairs
to the callback function, all I needed to do was get the name of the
Dispatch object doing the logging, and have the callback do the
necessary formatting based on the destination, but getting the name of
the Dispatch object is proving to be beyond my very measly perl
programming skills!
Any help would be greatly appreciated!
Thanks,
-Dan
(e-mail address removed)
(remove reverse("nospam") to reply via email.) Spambots are getting
waaay too smart nowadays!
======================
Sample code follows:
======================
#!/usr/local/bin/perl -w
use Log:ispatch;
use Log:ispatch::Email::MailSend;
use Log:ispatch::File;
use Data:umper;
$sub = sub { my %p = @_;
##############################################
# if $p{type} == "email" do some formatting on
$p{message};
# else do something else... or maybe nothing ;-P
##############################################
print Dumper(\%p);
return $p{message};
};
$dispatcher = Log:ispatch->new( callbacks => $sub);
$dispatcher->add( Log:ispatch::File->new( name => 'file1',
min_level => 'debug',
mode => 'append',
filename => 'logfile' ) );
$dispatcher->add( Log:ispatch::Email::MailSend->new( name =>
'email',
min_level => 'error',
to => [ qw( (e-mail address removed) (e-mail address removed) ) ],
subject => 'Oh no!!!!!!!!!!!') );
#################################################################
# Need "type" to automatically reflect dispatcher->outputs->name...
#################################################################
$dispatcher->log( level => 'error', message => "ERROR level logging
test\n", type=>"???" );
print Dumper(\$dispatcher);
#EOF
I'd like to use a callback function to do custom formatting of the
message based on whether the output is going to a logfile or email.
I.E. a one line entry if sent to logfile and a verbose description,
possibly including html, hyperlinks, etc if sent by email.
I figured since the log method supports sending arbitrary named pairs
to the callback function, all I needed to do was get the name of the
Dispatch object doing the logging, and have the callback do the
necessary formatting based on the destination, but getting the name of
the Dispatch object is proving to be beyond my very measly perl
programming skills!
Any help would be greatly appreciated!
Thanks,
-Dan
(e-mail address removed)
(remove reverse("nospam") to reply via email.) Spambots are getting
waaay too smart nowadays!
======================
Sample code follows:
======================
#!/usr/local/bin/perl -w
use Log:ispatch;
use Log:ispatch::Email::MailSend;
use Log:ispatch::File;
use Data:umper;
$sub = sub { my %p = @_;
##############################################
# if $p{type} == "email" do some formatting on
$p{message};
# else do something else... or maybe nothing ;-P
##############################################
print Dumper(\%p);
return $p{message};
};
$dispatcher = Log:ispatch->new( callbacks => $sub);
$dispatcher->add( Log:ispatch::File->new( name => 'file1',
min_level => 'debug',
mode => 'append',
filename => 'logfile' ) );
$dispatcher->add( Log:ispatch::Email::MailSend->new( name =>
'email',
min_level => 'error',
to => [ qw( (e-mail address removed) (e-mail address removed) ) ],
subject => 'Oh no!!!!!!!!!!!') );
#################################################################
# Need "type" to automatically reflect dispatcher->outputs->name...
#################################################################
$dispatcher->log( level => 'error', message => "ERROR level logging
test\n", type=>"???" );
print Dumper(\$dispatcher);
#EOF