On 2013-05-15 17:54, Duncan Garland wrote:
Hi,
Has anybody got some examples about how to use this.
It looks like you just have to put the following lines in the main package
before __PACKAGE__->setup():
use Log::Log4perl::Catalyst;
__PACKAGE__->log(Log::Log4perl::Catalyst->new('/path/to/log4perl.conf'));
That works up to a point in that the log messages are formatted as I want.
However they always go to the STDERR and not to the file given in
log4perl.conf. I've used the conf file in a test, so I know it works outside
Catalyst. I'm using the Catalyst development server, does that over-ride the
logger?
The other thing is that I don't really want to hardcode the filename. It should
be in the application's conf file. However, if I just stick it in there as so:
<Log4perl>
conf_file
/var/www/mymercedesservice.co.uk/fcgi/catalyst/mbfl2/lib/mbfl2/log4perl.conf
</Log4perl>
I can't access it via __PACKAGE__->config->{Log4perl}->{conf_file};
until after setup() has run.
Does that matter?
Thanks
Duncan
That's how I do it in all of our Catalyst apps:
In My::App:
=item finalize_config
Initializes the logger after the config file merging and loading is done.
=cut
sub finalize_config {
my $class = shift;
$class->next::method(@_);
$class->log(Log::Log4perl::Catalyst->new($class->config->{log}));
}
# Start the application
__PACKAGE__->setup;
around 'prepare' => sub {
my $orig = shift;
my $self = shift;
Log::Log4perl::MDC->remove();
my $c = $self->$orig(@_);
Log::Log4perl::MDC->put( "username", $c->user->username )
if $c->user_exists;
return $c;
};
This assumes that the l4p config is in the app config file under 'log' e.g.
from one of my Config::General config files:
<log>
log4perl.logger "WARN, FILE, MAIL"
log4perl.appender.FILE
"Log::Log4perl::Appender::File"
log4perl.appender.FILE.filename
"/home/nac/log/nac-web-request.log"
log4perl.appender.FILE.utf8 1
log4perl.appender.FILE.syswrite 1
log4perl.appender.FILE.layout
"Log::Log4perl::Layout::PatternLayout"
log4perl.appender.FILE.layout.ConversionPattern "%d{yyyy-MM-dd
HH:mm:ss} %-5p %X{username} %m%n"
log4perl.appender.MAIL
"Log::Dispatch::Email::MailSend"
log4perl.appender.MAIL.Threshold ERROR
log4perl.appender.MAIL.from
"[email protected]"<mailto:[email protected]>
log4perl.appender.MAIL.to
"[email protected]"<mailto:[email protected]>
log4perl.appender.MAIL.subject "[NAC::Web::Request]
errors"
log4perl.appender.MAIL.buffered 0
log4perl.appender.MAIL.layout "PatternLayout"
log4perl.appender.MAIL.layout.ConversionPattern "%d{yyyy-MM-dd
HH:mm:ss} %-5p %X{username} %m%n"
</log>
_______________________________________________
List: [email protected]<mailto:[email protected]>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/