Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^2: Log::Log4perl Module by chrestomanci
in thread Log::Log4perl Module by nvivek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found