|
From: <log...@pe...> - 2003-03-06 06:44:26
|
Welcome to the Log::Log4perl recipe of the week. Today:
============================================================
Log::Log4perl Recipe of the Week (#19):
Log4perl doesn't interpret my backslashes correctly!
============================================================
If you're using Log4perl's feature to specify the
configuration as a string in your program (as opposed to a
separate configuration file), chances are that you've
written it like this:
# *** WRONG! ***
Log::Log4perl->init( \ <<END_HERE);
log4perl.logger = WARN, A1
log4perl.appender.A1 = Log::Dispatch::Screen
log4perl.appender.A1.layout = \
Log::Log4perl::Layout::PatternLayout
log4perl.appender.A1.layout.ConversionPattern = %m%n
END_HERE
# *** WRONG! ***
and you're getting the following error message:
Layout not specified for appender A1 at .../Config.pm line 342.
What's wrong? The problem is that you're using a
here-document with substitution enabled ("<<END_HERE") and
that Perl won't interpret backslashes at line-ends as
continuation characters but will essentially throw them out.
So, in the code above, the layout line will look like
log4perl.appender.A1.layout =
to Log::Log4perl which causes it to report an error. To
interpret the backslash at the end of the line correctly as
a line-continuation character, use the non-interpreting mode
of the here-document like in
# *** RIGHT! ***
Log::Log4perl->init( \ <<'END_HERE');
log4perl.logger = WARN, A1
log4perl.appender.A1 = Log::Dispatch::Screen
log4perl.appender.A1.layout = \
Log::Log4perl::Layout::PatternLayout
log4perl.appender.A1.layout.ConversionPattern = %m%n
END_HERE
# *** RIGHT! ***
(note the single quotes around 'END_HERE') or use "q{...}"
instead of a here-document and Perl will treat the
backslashes at line-end as intended.
Have fun! Until next week.
-- Mike
###################################
# Mike Schilli #
# log...@pe... #
# http://perlmeister.com #
# http://log4perl.sourceforge.net #
###################################
|