You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by "Bachran, Michael" <MB...@onebridge.de> on 2001/12/11 13:51:34 UTC

Date Formatter for LogKitManagement

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

Re: Date Formatter for LogKitManagement

Posted by Peter Donald <pe...@apache.org>.
I just committed it into CVS - thanks!

On Tue, 11 Dec 2001 23:51, Bachran, Michael wrote:
> 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

-- 
Cheers,

Pete

------------------------------
Kitsch never goes out of style
------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Jeremias Maerki <je...@outline.ch>.
Hi Peter

Thanks for the getRTime() method! I've attached a Java class that
subclasses PatternFormatter to provide corrected relative, formatted
times. Sorry, that I didn't provide a proper patch, but I don't have the
time right now to do it properly. I hope you'll excuse me.

On Thu, 13 Dec 2001 19:03:10 +1100 Peter Donald wrote:
> On Thu, 13 Dec 2001 18:27, Jeremias Maerki wrote:
> > Well, if you guys are discussing date formatting issues, I'd like to
> > bring up something myself. I didn't have the time, yet, to make a patch
> > (SORRY!), but to fix a little problem it would by handy if there was
> > also a getRTime() method for relative timestamps. When formatting
> > relative timestamps the timezone information is irrelevant and results
> > in not so beatiful values to be printed out (+/- n hours) . Yes, I know,
> > this is a minor thing, but it would be nice to have and quick to
> > implement. What do you think?
> 
> I like. I added in a getRTime() method and am awaiting the patch to pretty 
> print the output if a parameter is specified ;)

Cheers,
Jeremias M�rki

mailto:jeremias.maerki@outline.ch

OUTLINE AG
Postfach 3954 - Rhynauerstr. 15 - CH-6002 Luzern
Fon +41 (41) 317 2020 - Fax +41 (41) 317 2029
Internet http://www.outline.ch

Re: Date Formatter for LogKitManagement

Posted by Peter Donald <pe...@apache.org>.
On Thu, 13 Dec 2001 18:27, Jeremias Maerki wrote:
> Well, if you guys are discussing date formatting issues, I'd like to
> bring up something myself. I didn't have the time, yet, to make a patch
> (SORRY!), but to fix a little problem it would by handy if there was
> also a getRTime() method for relative timestamps. When formatting
> relative timestamps the timezone information is irrelevant and results
> in not so beatiful values to be printed out (+/- n hours) . Yes, I know,
> this is a minor thing, but it would be nice to have and quick to
> implement. What do you think?

I like. I added in a getRTime() method and am awaiting the patch to pretty 
print the output if a parameter is specified ;)

-- 
Cheers,

Pete

*-----------------------------------------------------*
| Never argue with an idiot, they'll drag you down to |
| their level, and beat you with experience           |
*-----------------------------------------------------*

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Jeremias Maerki <je...@outline.ch>.
Well, if you guys are discussing date formatting issues, I'd like to
bring up something myself. I didn't have the time, yet, to make a patch
(SORRY!), but to fix a little problem it would by handy if there was
also a getRTime() method for relative timestamps. When formatting
relative timestamps the timezone information is irrelevant and results
in not so beatiful values to be printed out (+/- n hours) . Yes, I know,
this is a minor thing, but it would be nice to have and quick to
implement. What do you think?

On Wed, 12 Dec 2001 15:38:38 -0800 Bian Tan wrote:
> Good Catch! Chad Stansbury!
> 
> Pity, looks like Peter Donald already checked in the original
> Perhaps we can get the more optimal code checked in too?
> Is there an upcoming release of LogKit?
> 
> 
> -----Original Message-----
> From: Chad Stansbury [mailto:stansburyc@earthlink.net]
> Sent: Wednesday, December 12, 2001 3:09 PM
> 
> 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
> 

Cheers,
Jeremias Märki

mailto:jeremias.maerki@outline.ch

Postfach 3954 - Rhynauerstr. 15 - CH-6002 Luzern
Fon +41 (41) 317 2020 - Fax +41 (41) 317 2029
Internet http://www.outline.ch


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Peter Donald <pe...@apache.org>.
Thanks Bian and Chad. I just committed this to CVS ;)

On Thu, 13 Dec 2001 10:38, Bian Tan wrote:
> Good Catch! Chad Stansbury!
>
> Pity, looks like Peter Donald already checked in the original
> Perhaps we can get the more optimal code checked in too?
> Is there an upcoming release of LogKit?
>
>
> -----Original Message-----
> From: Chad Stansbury [mailto:stansburyc@earthlink.net]
> Sent: Wednesday, December 12, 2001 3:09 PM
>
> 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

-- 
Cheers,

Pete

-------------------------------------------------------
To fight and conquer in all your battles is not supreme 
excellence; supreme excellence consists in breaking the 
enemy's resistance without fighting. - Sun Tzu, 300 B.C.
-------------------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Date Formatter for LogKitManagement

Posted by Bian Tan <bt...@modulant.com>.
Good Catch! Chad Stansbury!

Pity, looks like Peter Donald already checked in the original
Perhaps we can get the more optimal code checked in too?
Is there an upcoming release of LogKit?


-----Original Message-----
From: Chad Stansbury [mailto:stansburyc@earthlink.net]
Sent: Wednesday, December 12, 2001 3:09 PM

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


Re: Date Formatter for LogKitManagement

Posted by Chad Stansbury <st...@earthlink.net>.
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" <bt...@modulant.com>
To: <av...@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:MBachran@onebridge.de]
>
>
> 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Chad Stansbury <st...@earthlink.net>.
I am hoping to make it log format-agnostic.  I've put in hooks to allow for
different log structures (e.g., plain-text vs. XML), and am going to allow
the user to describe the layout (i.e., create adaptors) of each line in the
log if it is plain text.  The first version will support plain text only.
The second version will support XML (but are people really going to use an
XML-formatted log?  Seems like a huge performance pig to me).

I'm only planning on supporting a post-mortem viewer in the initial release.
However, I have been careful to place hooks in the code to allow a real-time
viewer where possible.  Hopefully once I'm finished with the first version I
can get some feedback as to what would be desirable in a real-time viewer.

Chad

----- Original Message -----
From: "Peter Donald" <pe...@apache.org>
To: "Avalon Developers List" <av...@jakarta.apache.org>
Sent: Thursday, December 13, 2001 1:10 AM
Subject: Re: Date Formatter for LogKitManagement


> On Thu, 13 Dec 2001 09:55, Chad Stansbury wrote:
> > This may or may not be useful to you, but I am currently working on a
log
> > viewer that will enable you to view and search very large files (up to
> > 2,147,483,647 (Integer.MAX_VALUE) lines in length).  Part of its
> > functionality allows you to describe the format of the log file so that
it
> > can properly format whatever fields are contained in the log.  In other
> > words, even if you log a timestamp out as a long, you can view it with
this
> > tool as a formatted date.  This will say you a few precious microseconds
> > for each line you write to a log by not having to apply a DateFormat,
and
> > instead moves the expense of the formatting to the log viewer tool.
>
> Sounds good. One thing though - will you allow import from alternate log
> sources. For isntance currently one of our systems logs to syslog and
another
> is a home-brew log toolkit with funny formats. WOuld I be able to write
> adapters to receive log info from them?
>
> Oh and is it realtime or only post mortem? ie do you catch logs as they
run
> or do you only read the file once? etc.
>
> > I am hoping to make this tool freely available sometime by the end of
next
> > week (Dec 21).  If you are interested, please shoot me an email.  After
I
> > get the kinks worked out, I will most likely donate it to Jakarta (if
> > they'll have it).  Included are some stripped-down I/O classes that are
up
> > to 40% faster than their java.io equivalents.
>
> sounds interesting. Will look forward to it.
>
> --
> Cheers,
>
> Pete
>
> -------------------------------------------------
> "Sometimes its better to keep your mouth shut and
> let people think your an idiot, than to open it
> and remove all doubt."
> -------------------------------------------------
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Peter Donald <pe...@apache.org>.
On Thu, 13 Dec 2001 09:55, Chad Stansbury wrote:
> This may or may not be useful to you, but I am currently working on a log
> viewer that will enable you to view and search very large files (up to
> 2,147,483,647 (Integer.MAX_VALUE) lines in length).  Part of its
> functionality allows you to describe the format of the log file so that it
> can properly format whatever fields are contained in the log.  In other
> words, even if you log a timestamp out as a long, you can view it with this
> tool as a formatted date.  This will say you a few precious microseconds
> for each line you write to a log by not having to apply a DateFormat, and
> instead moves the expense of the formatting to the log viewer tool.

Sounds good. One thing though - will you allow import from alternate log 
sources. For isntance currently one of our systems logs to syslog and another 
is a home-brew log toolkit with funny formats. WOuld I be able to write 
adapters to receive log info from them?

Oh and is it realtime or only post mortem? ie do you catch logs as they run 
or do you only read the file once? etc.

> I am hoping to make this tool freely available sometime by the end of next
> week (Dec 21).  If you are interested, please shoot me an email.  After I
> get the kinks worked out, I will most likely donate it to Jakarta (if
> they'll have it).  Included are some stripped-down I/O classes that are up
> to 40% faster than their java.io equivalents.

sounds interesting. Will look forward to it.

-- 
Cheers,

Pete

-------------------------------------------------
"Sometimes its better to keep your mouth shut and 
let people think your an idiot, than to open it 
and remove all doubt." 
-------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date Formatter for LogKitManagement

Posted by Chad Stansbury <st...@earthlink.net>.
This may or may not be useful to you, but I am currently working on a log
viewer that will enable you to view and search very large files (up to
2,147,483,647 (Integer.MAX_VALUE) lines in length).  Part of its
functionality allows you to describe the format of the log file so that it
can properly format whatever fields are contained in the log.  In other
words, even if you log a timestamp out as a long, you can view it with this
tool as a formatted date.  This will say you a few precious microseconds for
each line you write to a log by not having to apply a DateFormat, and
instead moves the expense of the formatting to the log viewer tool.

I am hoping to make this tool freely available sometime by the end of next
week (Dec 21).  If you are interested, please shoot me an email.  After I
get the kinks worked out, I will most likely donate it to Jakarta (if
they'll have it).  Included are some stripped-down I/O classes that are up
to 40% faster than their java.io equivalents.

Chad Stansbury

----- Original Message -----
From: "Bian Tan" <bt...@modulant.com>
To: <av...@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:MBachran@onebridge.de]
>
>
> 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Date Formatter for LogKitManagement

Posted by Bian Tan <bt...@modulant.com>.
+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:MBachran@onebridge.de]


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