You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Felix Endres <fe...@roboception.de> on 2016/12/01 15:37:02 UTC

Unix Timestamps

Hi,
is it possible to print a unix timestamp, i.e. seconds since 1970 in the 
PatternLayout (or any other layout)? Optimally I would like a fractional 
pattern showing microseconds.

Apparently log4j 2 has a "%d{UNIX}" pattern, but this just prints "UNIX" 
in log4cxx. I am using the ubuntu liblog4cxx10, but I also tried the 
latest svn version.

Thanks and best regards,
Felix

-- 
Dr. Felix Endres

Roboception GmbH
Kaflerstr. 2
81241 M�nchen

phone: +49 89 8895 079 - 15
eMail: felix.endres@roboception.de
web: http://www.roboception.de

Sitz der Gesellschaft: Roboception GmbH, Kaflerstr. 4, 81241 M�nchen
Registereintrag: Amtsgericht M�nchen HRB 217783
Gesch�ftsf�hrer: Dr. Michael Suppa
USt. Ident. Nr.: DE299379772

Die in dieser E-Mail und den dazugeh�rigen Anh�ngen enthaltenen Informationen sind nur f�r den Adressaten bestimmt und k�nnen vertrauliche und/oder rechtlich gesch�tzte Informationen enthalten. Jeglicher Zugriff auf diese E-Mail durch andere Personen als den Adressaten ist untersagt. Sollten Sie diese Nachricht irrt�mlich erhalten haben, benachrichtigen Sie bitte den Absender und l�schen Sie diese Nachricht unverz�glich ohne sie zu kopieren oder zu verteilen oder ihren Inhalt an andere Personen weiterzugeben.

The information contained in this e-mail and any attachments is intended for the addressee only and may contain confidential and/or legally privileged information. Access to this e-mail by anyone else is unauthorized. If you have received this message by mistake please notify the sender, delete it immediately and do not copy or distribute it or disclose its contents to anyone.


Re: Unix Timestamps

Posted by Felix Endres <fe...@roboception.de>.
Hello Thorsten Sch�ning,

thank you for your quick answer.

On 12/01/2016 05:34 PM, Thorsten Sch�ning wrote:
> Guten Tag Felix Endres,
> am Donnerstag, 1. Dezember 2016 um 16:37 schrieben Sie:
>
>> is it possible to print a unix timestamp, i.e. seconds since 1970 in the
>> PatternLayout (or any other layout)? Optimally I would like a fractional
>> pattern showing microseconds.
> Is your question about the format or timezone handling? A format
> including fractionals is possible and the default already when only
> using "%d", but I'm pretty sure it's not supporting microseconds:
It's actually not about timezone handling. With timestamp I meant 
something like "1480614212.833892332", which is commonly used on unix, 
at least the integer seconds part.

>> %d{yyyy-MM-dd HH:mm:ss,SSS}
>> 2016-12-01 17:20:43,764
> Have a look at the classes datepatternconverter, strftimedateconverter
> and simpledateformat, which is used depending on your configuration
> and might support timezone related stuff. At least there some "Z"
> mentioned in simpledatformat, resulting in a calculation of timezone
> offsets in "RFC822TimeZoneToken".
I guess Robert Middleton's answer works for me. I may look into the 
classes you mention for microseconds though.

Thanks,
Felix

-- 
Sitz der Gesellschaft: Roboception GmbH, Kaflerstr. 4, 81241 M�nchen
Registereintrag: Amtsgericht M�nchen HRB 217783
Gesch�ftsf�hrer: Dr. Michael Suppa
USt. Ident. Nr.: DE299379772


Re: Unix Timestamps

Posted by Felix Endres <fe...@roboception.de>.
In the man page you linked to I found

*%s *The number of seconds since the Epoch, 1970-01-01 00:00:00
               +0000 (UTC). (TZ) (Calculated from/mktime(tm)/.)

There is nothing under a second, so I combine it with %d{SSS}:
log4j.appender.R.layout.ConversionPattern=[%p] [%d{%s}.%d{SSS}]: %m%n
 > [INFO] [1480614023.833]: message

Works for me :-)

Thank you so much!
Felix

On 12/01/2016 06:15 PM, Robert Middleton wrote:
> If I'm understanding the code correctly, in your %d{} specifier, you 
> can define a custom format using apr_strftime().  I'm assuming that 
> this means you can use the standard strftime() specifiers, but the 
> documentation for APR is somewhat lacking.
>
> http://man7.org/linux/man-pages/man3/strftime.3.html
>
> -Robert Middleton
>
> On Thu, Dec 1, 2016 at 11:34 AM, Thorsten Sch�ning 
> <tschoening@am-soft.de <ma...@am-soft.de>> wrote:
>
>     Guten Tag Felix Endres,
>     am Donnerstag, 1. Dezember 2016 um 16:37 schrieben Sie:
>
>     > is it possible to print a unix timestamp, i.e. seconds since
>     1970 in the
>     > PatternLayout (or any other layout)? Optimally I would like a
>     fractional
>     > pattern showing microseconds.
>
>     Is your question about the format or timezone handling? A format
>     including fractionals is possible and the default already when only
>     using "%d", but I'm pretty sure it's not supporting microseconds:
>
>     > %d{yyyy-MM-dd HH:mm:ss,SSS}
>     > 2016-12-01 17:20:43,764
>
>     Have a look at the classes datepatternconverter, strftimedateconverter
>     and simpledateformat, which is used depending on your configuration
>     and might support timezone related stuff. At least there some "Z"
>     mentioned in simpledatformat, resulting in a calculation of timezone
>     offsets in "RFC822TimeZoneToken".
>
>     Mit freundlichen Gr��en,
>
>     Thorsten Sch�ning
>
>     --
>     Thorsten Sch�ning       E-Mail: Thorsten.Schoening@AM-SoFT.de
>     AM-SoFT IT-Systeme http://www.AM-SoFT.de/
>
>     Telefon...........05151-  9468- 55
>     Fax...............05151-  9468- 88
>     Mobil..............0178-8 9468- 04
>
>     AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
>     AG Hannover HRB 207 694 - Gesch�ftsf�hrer: Andreas Muchow
>
>

-- 
Dr. Felix Endres

Roboception GmbH
Kaflerstr. 2
81241 M�nchen

phone: +49 89 8895 079 - 15
eMail: felix.endres@roboception.de
web: http://www.roboception.de

Sitz der Gesellschaft: Roboception GmbH, Kaflerstr. 4, 81241 M�nchen
Registereintrag: Amtsgericht M�nchen HRB 217783
Gesch�ftsf�hrer: Dr. Michael Suppa
USt. Ident. Nr.: DE299379772

Die in dieser E-Mail und den dazugeh�rigen Anh�ngen enthaltenen Informationen sind nur f�r den Adressaten bestimmt und k�nnen vertrauliche und/oder rechtlich gesch�tzte Informationen enthalten. Jeglicher Zugriff auf diese E-Mail durch andere Personen als den Adressaten ist untersagt. Sollten Sie diese Nachricht irrt�mlich erhalten haben, benachrichtigen Sie bitte den Absender und l�schen Sie diese Nachricht unverz�glich ohne sie zu kopieren oder zu verteilen oder ihren Inhalt an andere Personen weiterzugeben.

The information contained in this e-mail and any attachments is intended for the addressee only and may contain confidential and/or legally privileged information. Access to this e-mail by anyone else is unauthorized. If you have received this message by mistake please notify the sender, delete it immediately and do not copy or distribute it or disclose its contents to anyone.


Re: Unix Timestamps

Posted by Robert Middleton <os...@gmail.com>.
If I'm understanding the code correctly, in your %d{} specifier, you can
define a custom format using apr_strftime().  I'm assuming that this means
you can use the standard strftime() specifiers, but the documentation for
APR is somewhat lacking.

http://man7.org/linux/man-pages/man3/strftime.3.html

-Robert Middleton

On Thu, Dec 1, 2016 at 11:34 AM, Thorsten Schöning <ts...@am-soft.de>
wrote:

> Guten Tag Felix Endres,
> am Donnerstag, 1. Dezember 2016 um 16:37 schrieben Sie:
>
> > is it possible to print a unix timestamp, i.e. seconds since 1970 in the
> > PatternLayout (or any other layout)? Optimally I would like a fractional
> > pattern showing microseconds.
>
> Is your question about the format or timezone handling? A format
> including fractionals is possible and the default already when only
> using "%d", but I'm pretty sure it's not supporting microseconds:
>
> > %d{yyyy-MM-dd HH:mm:ss,SSS}
> > 2016-12-01 17:20:43,764
>
> Have a look at the classes datepatternconverter, strftimedateconverter
> and simpledateformat, which is used depending on your configuration
> and might support timezone related stuff. At least there some "Z"
> mentioned in simpledatformat, resulting in a calculation of timezone
> offsets in "RFC822TimeZoneToken".
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
>
> Telefon...........05151-  9468- 55
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
>
>

Re: Unix Timestamps

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Felix Endres,
am Donnerstag, 1. Dezember 2016 um 16:37 schrieben Sie:

> is it possible to print a unix timestamp, i.e. seconds since 1970 in the
> PatternLayout (or any other layout)? Optimally I would like a fractional
> pattern showing microseconds.

Is your question about the format or timezone handling? A format
including fractionals is possible and the default already when only
using "%d", but I'm pretty sure it's not supporting microseconds:

> %d{yyyy-MM-dd HH:mm:ss,SSS}
> 2016-12-01 17:20:43,764

Have a look at the classes datepatternconverter, strftimedateconverter
and simpledateformat, which is used depending on your configuration
and might support timezone related stuff. At least there some "Z"
mentioned in simpledatformat, resulting in a calculation of timezone
offsets in "RFC822TimeZoneToken".

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow