logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: DailyRollingFileAppender (newest on top)
Date Sat, 12 Dec 2009 15:22:30 GMT

On Dec 8, 2009, at 3:48 PM, mc1392 wrote:

> Is there any way to get the log entries to have the most recent on top?
> Currently I am using html layout and the newest entry ends up at the bottom
> of the file.
> I'd like the newest on top.

Appending content is within the capabilities of java.io, prepending is not.   To do it without
support from the IO system, you'd end up rewriting the entire log file for every entry.  
logging is write often, read rarely, so it makes more sense to optimize writing. 

Since you are using the HTMLLayout and presumably reading the log file within a modern browser,
you could instead use the XMLLayout, write the log in the traditional order and then use an
XSLT stylesheet to format and reorder the entries in the browser.  To do that, you'd need
a shell document,


<!DOCTYPE logfile [
<!ENTITY events SYSTEM 'events.xml'>
<?xml-stylesheet href="mystylesheet.xsl"?>

And have your file appender write to events.xml.  A browser reading logfile.xml will read
in the contents of events.xml and then will run the transform in mystylesheet.xsl which could
convert the logging events to the order and format of your choice.
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message