For the speed freaks like myself, here's another optimization to the Date formatter code. You can improve upon the speed by removing the Date instantiation (which in the quoted code will be invoked for each line being logged), and replacing w/ a setTime call... The new code would be:
import java.util.Date; import java.text.SimpleDateFormat; SimpleDateFormat m_dateFormatter = null; Date m_date = new Date(); protected String getTime( final long time, final String format ) { if ( format == null ){ return Long.toString( time ); } if (m_dateFormatter == null) { m_dateFormatter = new SimpleDateFormat( format ); } m_date.setTime( System.currentTimeMillis() ); return( m_dateformatter.format( m_date ) ); } Chad Stansbury ----- Original Message ----- From: "Bian Tan" <[EMAIL PROTECTED]> To: <avalon-dev@jakarta.apache.org> Sent: Wednesday, December 12, 2001 11:04 AM Subject: RE: Date Formatter for LogKitManagement > +1 > I would love to see date formatting in LogKit, to me this is an oversight as > the long time format is simply not human-readable. > > It would be better to cache the date formatter object, already you are > incurring the construction of a new date object everytime a message is > logged for each target that uses the formatter and this can add up in an app > with intense logging. No need to compound that by creating the date > formatter object over and over again. > > + import java.util.Date; > + import java.text.SimpleDateFormat; > ... > + SimpleDateFormat m_dateFormatter = null; > > protected String getTime( final long time, final String format ) > { > + if ( format == null ) > + { > return Long.toString( time ); > + } > + if (m_dateFormatter == null) { > + m_dateFormatter = new SimpleDateFormat( format ); > + } > + return( m_dateformatter.format( new Date( time ) ) ); > } > > -biant > > > -----Original Message----- > From: Bachran, Michael [mailto:[EMAIL PROTECTED] > > > Hi, > I would like to use a formatter using the simple date format for dates. It > might be usefull to everyone to have this integrated in the > LogKitManagement. So I would like to suggest patching the PatternFormatter > like this: > + import java.util.Date; > + import java.text.SimpleDateFormat; > ... > protected String getTime( final long time, final String format ) > { > + if ( format == null ) > + { > return Long.toString( time ); > + } > + SimpleDateFormat simpleDateFormat = new SimpleDateFormat( format ); > + return( simpleDateFormat.format( new Date( time ) ) ); > } > > > What do you think? > Michael > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>