Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Log4Perl issue

by palette (Scribe)
on Jan 03, 2007 at 14:58 UTC ( #592767=perlquestion: print w/replies, xml ) Need Help??

palette has asked for the wisdom of the Perl Monks concerning the following question:

Whats the difference between Log::Dispatch::File and Log::Log4perl::Appender::File in Log4perl module.

I have a conf file in which for module 'a' I am using Log::Log4perl::Appender::File, a.log and for module 'b' I am trying to log to another file called b.log using Log::Dispatch::File

Now the module 'a' and module 'b' are invoked simultaneously but I am able to find module a's log in the b.log file. I expect module 'a' log into a.log and module 'b' into b.log irrespective of whether both of them are invoked at the same time.

Can any one tell me what might be the cause of this problem.

Replies are listed 'Best First'.
Re: Log4Perl issue
by shigetsu (Hermit) on Jan 03, 2007 at 15:01 UTC
    Is it possible to see some related code?
Re: Log4Perl issue
by Anonymous Monk on Jan 03, 2007 at 15:31 UTC
    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();)
      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?
      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.
Re: Log4Perl issue
by Anonymous Monk on Jan 03, 2007 at 15:35 UTC
    From the documentation
    package Bar::Twix; use Log::Log4perl qw(:easy); sub eat { DEBUG("Twix mjam"); } package Bar::Mars; use Log::Log4perl qw(:easy); sub eat { INFO("Mars mjam"); } package main; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init( { level => $DEBUG, file => ">>test.log", category => "Bar::Twix", layout => '%F{1}-%L-%M: %m%n' }, { level => $DEBUG, file => "STDOUT", category => "Bar::Mars", layout => '%m%n' }, ); Bar::Twix::eat(); Bar::Mars::eat();
Re: Log4Perl issue
by Anonymous Monk on Jan 03, 2007 at 15:10 UTC
    Can any one tell me what might be the cause of this problem.

    Its your configuration.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-09-26 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?