Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Log::Log4perl Module

by chrestomanci (Priest)
on Feb 12, 2011 at 10:17 UTC ( [id://887747]=note: print w/replies, xml ) Need Help??


in reply to Re: Log::Log4perl Module
in thread Log::Log4perl Module

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.

Replies are listed 'Best First'.
Re^3: Log::Log4perl Module
by nvivek (Vicar) on Feb 12, 2011 at 12:50 UTC

    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://887747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-19 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found