http://qs1969.pair.com?node_id=594361


in reply to Re: log file in Log4perl
in thread log file in Log4perl

Hi,

Can I know why a "\" is required at the end of every line of the sub. As per the CPAN description it seems that we have to send reference of the method. If wrong do correct me.

Thanks

Replies are listed 'Best First'.
Re^3: log file in Log4perl
by ferreira (Chaplain) on Jan 12, 2007 at 12:07 UTC

    In the piece of code you mentioned, you are not writing Perl code but a properties file (with lines "key = value") which is read by this statement:

    Log::Log4perl::init_and_watch('/etc/log4perl.conf',5);

    The value can be extended for many lines if they end in "\". There is more info in the FAQ within Log-Log4perl distribution.

Re^3: log file in Log4perl
by jasonk (Parson) on Jan 12, 2007 at 14:23 UTC

    Because the Log4perl configuration file format requires each configuration item to be on a single line. You can continue a line onto the next line by ending it in a backslash, or you can just type it out as one really long line. If you review the documentation on CPAN again, you will notice that all of the examples use very short subs, and none of them span more than one line.

    The method I normally use for approaching this is something like...

    # config file log4perl.logger.ClassA = DEBUG, ClassA log4perl.appender.ClassA = Log::Log4perl::Appender::File log4perl.appender.ClassA.filename = sub { log_filename() } # in the main code use POSIX 'strftime'; sub log_filename { return strftime( "/tmp/ClassA%Y%m%d.log", localtime ); } Log::Log4perl::init_and_watch('/etc/log4perl.conf',5); my $mylog = Log::Log4perl->get_logger();

    We're not surrounded, we're in a target-rich environment!