Log::Log4perl::Appender - Log appender object
use Log::Log4perl::Appender; # Define a logger my $logger = Log::Log4perl->get_logger("abc.def.ghi"); # Define a layout my $layout = Log::Log4perl::Layout::PatternLayout->("%d (%F:%L)> %m"); # Define an appender my $appender = Log::Log4perl::Appender->new("Log::Dispatch::Screen" name => 'dumpy'); # Set the appender's layout $appender->layout($layout); $logger->add_appender($appender);
This class is a wrapper around the Log::Dispatch::* collection of dispatchers. It hides the idiosyncrasies of Log::Dispatch (every dispatcher gotta have a name, but there's no accessor to retrieve it) from Log::Log4perl and yet re-uses the extremely useful variety of dispatchers already created and tested in Log::Dispatch.
Log::Dispatch::*
Log::Dispatch
Log::Log4perl
The constructor new() takes the name of the Log::Dispatcher class to be created as a string (!) argument, optionally followed by a number of Log::Dispatcher::Whatever-specific parameters, for example:
new()
Log::Dispatcher
Log::Dispatcher::Whatever
# Define an appender my $appender = Log::Log4perl::Appender->new("Log::Dispatch::File" name => 'dumpy', file => 'out.log');
If no name parameter is specified, the appender object will create a unique one (format appNNN), which can be retrieved later via the name() method:
name
appNNN
name()
print "The appender's name is ", $appender->name(), "\n";
The Log::Log4perl::Appender will relay the log_to() method to the Log::Dispatch::* object it carries in its womb and can therefore be used by Log::Log4perl just like a Log::Dispatch::* appender.
Log::Log4perl::Appender
log_to()
Mike Schilli, <m@perlmeister.com>
To install Log::Log4perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Log4perl
CPAN shell
perl -MCPAN -e shell install Log::Log4perl
For more information on module installation, please visit the detailed CPAN module installation guide.