Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Log4Perl issue

by Anonymous Monk
on Jan 03, 2007 at 15:31 UTC ( [id://592775]=note: print w/replies, xml ) Need Help??


in reply to Log4Perl issue

Here is a working example
use strict; use warnings; use Log::Log4perl; Log::Log4perl::init( \' log4perl.logger.Groceries=DEBUG, A1 log4perl.appender.A1=Log::Dispatch::File log4perl.appender.A1.filename=Groceries.log log4perl.appender.A1.mode=append log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m% +n log4perl.logger.Junk=DEBUG, A2 log4perl.appender.A2=Log::Log4perl::Appender::File log4perl.appender.A2.filename=Junk.log log4perl.appender.A2.mode=append log4perl.appender.A2.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.A2.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m% +n ' ); my $log = Log::Log4perl::get_logger("Groceries"); $log->info("Important Groceries Info!"); $log = Log::Log4perl::get_logger("Junk"); $log->info("Important Junk Info!");
You're probably only using the root logger (my $log = get_logger();)

Replies are listed 'Best First'.
Re^2: Log4Perl issue
by palette (Scribe) on Jan 03, 2007 at 16:26 UTC
    The issue is sometimes I am able to see module 'a' log in the a.log file.
    But in case module 'b'is running then module a's log is written in b.log


    log4perl.logger.a = DEBUG, a
    log4perl.b=DEBUG, b
    log4perl.appender.a = Log::Log4perl::Appender::File
    log4perl.appender.a.filename = a.log
    log4perl.appender.a.max = 15
    log4perl.appender.a.DatePattern = yyyy-MM-dd
    log4perl.appender.a.mode = append
    log4perl.appender.a.TZ = BST
    log4perl.appender.a.layout = Log::Log4perl::Layout::PatternLayout
    log4perl.appender.a.layout.ConversionPattern = %d %c - %m%n

    log4perl.appender.b=Log::Dispatch::File
    log4perl.appender.b.filename=b.log
    log4perl.appender.b.mode=append
    log4perl.appender.b.layout=Log::Log4perl::Layout::PatternLayout
    log4perl.appender.b.layout.ConversionPattern = %d %c - %m%n


    package a;
    BEGIN {
    Log::Log4perl::init_and_watch('/etc/log4perl.conf',30);
    $__PACKAGE__::mylog=Log::Log4perl->get_logger();
    }


    the module b is defined inside b.pl script
    BEGIN {
    package b;
    Log::Log4perl::init_and_watch('log4perl.conf',30);
    $__PACKAGE__::mylog=Log::Log4perl->get_logger(__PACKAGE__);
    }



      What is log4perl.b=DEBUG, b?
        Sorry!!
        It's typo its log4perl.logger.b = DEBUG, b

        But anyway in the code its fine.
Re^2: Log4Perl issue
by palette (Scribe) on Jan 11, 2007 at 15:06 UTC
    Hi,

    Yes both the package a and package b has the line

    Log::Log4perl::init_and_watch('/etc/log4perl.conf',30); $__PACKAGE__::mylog=Log::Log4perl->get_logger();

    but having get_logger without the package name makes any difference. The same script I have in my development box both are logged separately but when both the code runs at the same time I think the problem is there.

    One more information

    package a is saved in a file called a.pm and package b is inside a perl script .pl and defined the package b inside the BEGIN block and not returning a 1;

    Does that makes any difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found