You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Rob Walker <ro...@softsell.com> on 2001/04/05 20:24:33 UTC

Time stamping of log messages

As a new user I may be raising an obvious or old question here. Is 
there some way log messages can be timestamped when raised 
as opposed to when logged. It's not a big deal for local logging, but 
when logging over slow network links the messages in local file 
based logs show different timestamps to those displayed on 
remote clients.

Anyone else come across this one, or suggested a workaround?

-- Rob

SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Rob Walker <ro...@softsell.com>.
Thanks Ceki
- Rob

SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Ceki Gülcü <cg...@qos.ch>.


At 18:06 11.04.2001 +0100, you wrote:
>Ceki,
>
>> 
>> What Paul described is certainly true for the newest code in our 
>CVS rep. As far as I know, 1.1b1 or any previous version the 
>PatternLayout does time stamping when formatting the event, not 
>when the event was created. This was a silly bug that has been 
>corrected in the code in our CVS rep. In other words, in 1.1b2 and 
>later versions, PatternLayout will use the time stamp that was 
>minted when the LoggingEvent was created or approximately at the 
>same time as the logging statement was invoked. Hope this further 
>clarifies the matter, Ceki
>
>Many thanks - was beginning to think I was seeing things!
>
>Not that familiar with CVS or the Dev. source trees. Can I just grab 
>a copy, and are there any "stability" issues i.e. whay stage is 
>version 1.1b2 in the develop/test cycle?

1.1b1 is basically a maintenance release ironing out rough edges with 1.0.4. On the other hand, 1.1b2 has a number of changes, in particular the JavaBeans type configuration added by Anders Kristensen. The new code passes our regression tests so it should be quite OK. 

The problem with code in our CVS repository is that changes can be committed before being fully tested. So the code in the CVS rep is not guaranteed to work well in production environments. 

Coming back to the issue at hand, I suggest that you simply patch 1.1b1 by changing
org/apache/log4j/helpers/PatternParser.java. See http://jakarta.apache.org/site/cvsindex.html for changes that occured in PatternParser.java.

The relevant patch is copied below:


===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/PatternParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jakarta-log4j/src/java/org/apache/log4j/helpers/PatternParser.java  2001/01/22 10:57:27     1.4
+++ jakarta-log4j/src/java/org/apache/log4j/helpers/PatternParser.java  2001/03/20 16:05:46     1.5
@@ -22,6 +22,7 @@
 
 // Contributors:   Nelson Minar <(n...@monkey.org>
 //                 Igor E. Poteryaev <ja...@mail.ru>  
+//                 Reinhard Deschler <re...@web.de> 
 
 /**
    Most of the work of the {@link org.apache.log4j.PatternLayout} class
@@ -426,7 +427,7 @@
 
     public
     String convert(LoggingEvent event) {
-      date.setTime(System.currentTimeMillis());
+      date.setTime(event.timeStamp);
       return df.format(date);
     }
   }
@@ -477,7 +478,7 @@
 
        // We substract 1 from 'len' when assigning to 'end' to avoid out of
        // bounds exception in return r.substring(end+1, len). This can happen if
-       // precision is 1 and the category name ends with a dot. you 
+       // precision is 1 and the category name ends with a dot. 
        int end = len -1 ;
        for(int i = precision; i > 0; i--) {      
          end = n.lastIndexOf('.', end-1);



The modification that we are interested in is replacing 

 date.setTime(System.currentTimeMillis());

with

  date.setTime(event.timeStamp);

on line 430 or so in PatternParser.java. Regards, Ceki

ps: It's a lot of words for not much. As I said, it was a silly bug.



--
Ceki Gülcü     Web: http://qos.ch 
email: cgu@qos.ch or ceki_gulcu@yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Rob Walker <ro...@softsell.com>.
Ceki,

> 
> What Paul described is certainly true for the newest code in our 
CVS rep. As far as I know, 1.1b1 or any previous version the 
PatternLayout does time stamping when formatting the event, not 
when the event was created. This was a silly bug that has been 
corrected in the code in our CVS rep. In other words, in 1.1b2 and 
later versions, PatternLayout will use the time stamp that was 
minted when the LoggingEvent was created or approximately at the 
same time as the logging statement was invoked. Hope this further 
clarifies the matter, Ceki

Many thanks - was beginning to think I was seeing things!

Not that familiar with CVS or the Dev. source trees. Can I just grab 
a copy, and are there any "stability" issues i.e. whay stage is 
version 1.1b2 in the develop/test cycle?

Regards

-- rob --


SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Ceki Gülcü <cg...@qos.ch>.
At 19:48 08.04.2001 +0100, you wrote:
>Paul
>
>> I'm work on an application that logs across timezones.  The timestamp I
>> see in the DOS box inside of PC Anywhere connecting to the remote
>> machine is one hour different than the timestamp I see in a local DOS
>> box being fed by a SimpleSocketServer.  Since the SimpleSocketServer
>> also receives events from servers in the same timezone, the log file is
>> consistent in using a single timezone (the local one).
>> 
>> Does this explain what you are seeing?
>
>Could well be it ... never though the to check the remote machine in 
>question. Thanks for the tip, I'll look into whether this was the cause.

What Paul described is certainly true for the newest code in our CVS rep. As far as I know, 1.1b1 or any previous version the PatternLayout does time stamping when formatting the event, not when the event was created. This was a silly bug that has been corrected in the code in our CVS rep. In other words, in 1.1b2 and later versions, PatternLayout will use the time stamp that was minted when the LoggingEvent was created or approximately at the same time as the logging statement was invoked. Hope this further clarifies the matter, Ceki




>-- Rob --
>
>
>
>SoftSell Business Systems, Ltd.
>' testing solutions for a changing world '
> 
>+44 (20) 7488 3470
>www.softsell.com
>robw@softsell.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org

--
Ceki Gülcü     Web: http://qos.ch 
email: cgu@qos.ch or ceki_gulcu@yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Rob Walker <ro...@softsell.com>.
Paul

> I'm work on an application that logs across timezones.  The timestamp I
> see in the DOS box inside of PC Anywhere connecting to the remote
> machine is one hour different than the timestamp I see in a local DOS
> box being fed by a SimpleSocketServer.  Since the SimpleSocketServer
> also receives events from servers in the same timezone, the log file is
> consistent in using a single timezone (the local one).
> 
> Does this explain what you are seeing?

Could well be it ... never though the to check the remote machine in 
question. Thanks for the tip, I'll look into whether this was the cause.

-- Rob --



SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Paul Glezen <pg...@atdial.net>.
Rob Walker wrote:
> 
> As a new user I may be raising an obvious or old question here. Is
> there some way log messages can be timestamped when raised
> as opposed to when logged. It's not a big deal for local logging, but
> when logging over slow network links the messages in local file
> based logs show different timestamps to those displayed on
> remote clients.

Hi Rob,

The timestamp is created along with the LoggingEvent in UTC format. 
Even with slow connections, this shouldn't be an issue since the event
is created before it is sent to any appenders.  If you're logging across
timezones, then by default you'll see the time in whatever timezone the
converter is running in.

I'm work on an application that logs across timezones.  The timestamp I
see in the DOS box inside of PC Anywhere connecting to the remote
machine is one hour different than the timestamp I see in a local DOS
box being fed by a SimpleSocketServer.  Since the SimpleSocketServer
also receives events from servers in the same timezone, the log file is
consistent in using a single timezone (the local one).

Does this explain what you are seeing?

- Paul
-- 
Beware of bugs in the above code.  I have
only proved it correct, not tried it.
-Don Knuth

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


example of socketadapter

Posted by Sachin Wadhwa <sw...@dwl.com>.
Hi Can anyone send me some example code of using socket adapter in EJBs
sac



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Rob Walker <ro...@softsell.com>.
Anuj,

> When you use PatternLayout you can specify a data attribute.  
It's pretty
> sweet.  Check out the javadocs for PatternLayout.
> Anuj.

Thanks for this ... maybe I'm being think but I can't see any 
reference to a data attribute in PatternLayout. Can you point me at 
the right spot.

Just to clarify, what I'm looking for is to get the time of a message 
stamped at the time it is raised not when it eventually gets logged.

-- Rob --


SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Time stamping of log messages

Posted by Anuj Agrawal <ag...@lucent.com>.
When you use PatternLayout you can specify a data attribute.  It's pretty
sweet.  Check out the javadocs for PatternLayout.
Anuj.

Rob Walker wrote:

> As a new user I may be raising an obvious or old question here. Is
> there some way log messages can be timestamped when raised
> as opposed to when logged. It's not a big deal for local logging, but
> when logging over slow network links the messages in local file
> based logs show different timestamps to those displayed on
> remote clients.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org