log4j is logging errors based on level. Is there a way to log errors based on timestamp?
+1
A:
log4j can be configured to log with the timestamp in the line. At least that's what I think you're asking.
Use %d in your PatternLayout.
Now I understand: log4j is asynchronous, so you may have time stamps out of order.
If you want synchronous logging, I believe that is possible, but it is slower.
Nathan
2009-02-19 22:08:08
Thanks Nathan.2009-02-19 14:47:01,288 DEBUG [com.catalystwms.core.persistence.TransactionContext] 2009-02-19 14:54:27,429 INFO [com.catalystwms.tms.services.background.purge2009-02-19 14:47:01,288 DEBUG.....My question is Can we log the message based on timestamps priority?
2009-02-19 22:31:20
Log entries are executed in order of entry (this would make the timestamps ordered.) How do you prioritize time stamps exactly?
Nathan
2009-02-19 22:56:46
Can we make 1.2009-02-19 14:47:01,288 DEBUG2.2009-02-19 14:47:01,288 DEBUG3.2009-02-19 14:54:27,429 INFO [com.catalystwms.tms.services.background.purge]
2009-02-19 23:07:33
If you're looking for a way to see at what times a specific action occurred, it can be done, but not with log4j. It will not modify a previously entered log entry. You could throw this stuff into a database and group by the log description ([com.cata....purge])
Nathan
2009-02-19 23:16:45
Thanks.Tasks are executing based on sequential timestamp.I do n't have idea why timestamps are not in sequence.
2009-02-19 23:21:24
My question why it is not executed timestamp order like (1)14:47:01 (2)14:47:01 (3)14:54:27.I am expecting sequential order
2009-02-19 23:22:19
Got it. It's due to log4j being asynchronous.
Nathan
2009-02-19 23:33:32
Yes. Is there a way to get it synchronous?
2009-02-20 14:39:22
You'd probably be better off inserting this in a DB and then sorting on the date entered. You don't want your logging code blocking the execution of your business logic.
Nathan
2009-03-11 20:34:45
A:
If you are logging to file with log4j, the timestamp is created when the logging event is created. So when the (debug, info, ...) method is invoked. If you have multiple threads running it could be that the messages are not written written to file in the same order as the timestamp.
If you require the log-lines to be sorted in order, use a JDBC Appender and log to the database. Then you can query the database and sort on timestamp.
Edwin
2009-02-21 12:36:11