Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Log::Log4perl Module

by Khen1950fx (Canon)
on Feb 12, 2011 at 06:26 UTC ( [id://887734]=note: print w/replies, xml ) Need Help??


in reply to Log::Log4perl Module

Here's the FAQ about the problem. It'll show you how to set the additivity flag to 0.

Replies are listed 'Best First'.
Re^2: Log::Log4perl Module
by chrestomanci (Priest) on Feb 12, 2011 at 10:17 UTC

    I think you have mis-understood nvivek's question. The FAQ entry you linked to covers the situation where due to the way log4perl is configured, and how multiple loggers interact with each other a single call to $log->warn('some message'); results in duplicate copies of a single message appearing.

    I think nvivek has a different situation. He has written some code like this:

    sub connect_to_service { my $service_url = shift; my $logger = Log::Log4perl->get_logger(); my $max_attempts = 10; ATTEMPT: while( $max_attempts-- ) { my $connection = connect($service_url, {timeout=>30}); if( defined $connection ) { $logger->info("Connected OK to $service_url"); return $connection; } else { $logger->error("Error connecting to $service_url, will ret +ry"); } } # If this line is reached then all 10 connection attempts failed $logger->logdie("Could not connect to $service_url"); }

    nvivek wants to see in his logs something like this:

    ERROR: Error connecting to soap//service, will retry [last message repeated 10 times] FATAL: Could not connect to soap//service

    To do this, you would need to run a log::log4perl appender that retains state, and compares the current message with the previous one, and if they are similar enough would not log the message, but instead would increment an internal count. When it sees a different message it would then emit the last message repeated $n times message. (The appender could not simply compare for identical messages, because most layouts pretend log messages with date-stamps or the like.)

    Unfortunately I don't know of an appender that fits this requirement, and I don't want to post the result of a google search without taking the time to understand it and make sure that it matches what the supplicant asked for.

      Thanks a lot chrestomanci. You understood my requirement correctly. I am also searching it. If you find the result, post the answer.
      Thanks & Regards,
      nvivek.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found