You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Huber Christian (IT-DIWA)" <Ch...@swisslife.de> on 2010/05/07 14:24:21 UTC
Usage of EnhanedPatternLayout
Hi all,
I stumbled across the javadoc (log4j-1.2.14) for the EnhancedPatternLayout and would like to use the properties conversion pattern to pass additional information to the log output. Unfortunately I have not found out how this can be done, I saw that a LoggingEvent can be given a Map with properties during construction but usually you do not instantiate a LoggingEvent but let the Logger take care of it (the documentation even states that it is an internal representation so I would not try to use it directly). On the other hand you cannot pass any properties etc to a Logger or LoggerFactory. So I am kinda stumped here what I am missing.
Could anyone give me any pointers on this?
Thanks, Chris
Re: AW: Usage of EnhanedPatternLayout
Posted by Peter Fuerholz <Pe...@ascom.ch>.
Hi Scott,
thanks for your response. I was unsure, if Log4j already had a solution
for the problem mentioned. As it seems there is no boilerplate solution
available.
What I could do is configuring a filename like this
<param name="File" value="logfile${sessionId}.log" />
Before starting Log4j I could set the 'sessionId'-property (via
System.setProperty("sessionId", <id>)) with the current session-id from
the client-server-communication. I tried that and it works basically.
I currently use a RollingFileAppender with constrained file sizes and
backup indexes. The problem is now, that each program run adds a new set
of log file and inflates the total amount of log data. Example:
logfile15.log, logfile15.log.1, logfile15.log.2
logfile34.log, logfile34.log.1, logfile34.log.2
logfile62.log, logfile62.log.1, logfile62.log.2
Depending on the range of session-ids the logged data get almost never
deleted at all... ;-(
Instead of using a session-id I am thinking about finding a way to count
the currently run program instances...
Thanks,
Peter
Scott Deboy <sc...@gmail.com> wrote on 10.05.2010 19:55:34:
> [image removed]
>
> ----- Message from Scott Deboy <sc...@gmail.com> on Thu, 6 May
> 2010 11:50:16 -0700 -----
>
> To:
>
> Log4J Users List <lo...@logging.apache.org>
>
> Subject:
>
> Re: Logging multiple Webstart client instances?
>
> In a prior life I used a subclass of RollingFileAppender which set the
file
> name to include hours, minutes and seconds, but rolled based on size..I
> think if a filenamepattern was supported for the activeFileName in
> TimeBasedRollingPolicy, this would solve your problem...
>
> Scott
>
> On Tue, May 4, 2010 at 2:47 AM, Peter Fuerholz
<Pe...@ascom.ch>wrote:
>
> > Hi there,
> >
> > I have a signed WebStart application which logs defaultly into the
current
> > user's home directory. (If I use a relative path the log file is saved
> > under a browser specific path which is not very user friendly.) There
are
> > now cases where it is sensible to start this WebStart application
twice or
> > more times. In this case, all program instances write to the same log
file
> > which makes it very difficult to read.
> >
> > I came up with following two solutions:
> > - Put each log file into a session-specific path, e.g.
> > <home>/.<application-name>/<session-id>/<filename>
> > session-id must be a program instance specific identifier
> > - Use MDC. Distinguish the different client instances by using
different
> > MDC-keys.
> > - This could be a problem using RollingFileAppender (Messages may get
> > messed up according older mailing list entries?)
> > - Produces a lot of extra data since the cases, where > 1 program
> > instances are running, are rather few
> >
> > Is there a default behaviour how to solve this issue?
> > Any help appreciated.
> >
> > Yours,
> > Peter
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
Re: AW: Usage of EnhanedPatternLayout
Posted by Scott Deboy <sc...@gmail.com>.
MDC are represented as properties, and are the only way to get a property
associated with a LoggingEvent without having access to the LoggingEvent
instance itself..
The documentation's current state can be explained by the fact that MDC
predates support for general LoggingEvent 'properties', but
implementation-wise they are all properties of the LoggingEvent.
Scott
On Mon, May 10, 2010 at 6:33 AM, Huber Christian (IT-DIWA) <
Christian.Huber@swisslife.de> wrote:
> It seems you have a point there, %X{propname} creates the same output as
> %properties{propname}
>
> The javadoc on those to conversion patterns though suggests that this are
> two different patterns:
>
> _X_ -- Used to output _the MDC_ (mapped diagnostic context) associated
> with _the thread_ that generated the logging event...
>
> _properties_ -- Used to output _the Properties_ associated with the
> _logging event_...
>
> This is at best misleading and imo rather a bug in the documentation.
>
> @All: Thanks for your help :-)
>
>
> -----Ursprüngliche Nachricht-----
> Von: Curt Arnold [mailto:curt.arnld@gmail.com] Im Auftrag von Curt Arnold
> Gesendet: Montag, 10. Mai 2010 15:21
> An: Log4J Users List
> Betreff: Re: AW: Usage of EnhanedPatternLayout
>
>
> On May 10, 2010, at 5:48 AM, Huber Christian (IT-DIWA) wrote:
>
> > I would use it when I will try to implement the usage of this class, but
> so far I am trying to understand how those properties should/can be set.
> >
>
> I may be off on some nuance, but I believe %properties is a synonym for %x
> in the same way that %logger is a synonym for %c.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
AW: AW: Usage of EnhanedPatternLayout
Posted by "Huber Christian (IT-DIWA)" <Ch...@swisslife.de>.
It seems you have a point there, %X{propname} creates the same output as %properties{propname}
The javadoc on those to conversion patterns though suggests that this are two different patterns:
_X_ -- Used to output _the MDC_ (mapped diagnostic context) associated with _the thread_ that generated the logging event...
_properties_ -- Used to output _the Properties_ associated with the _logging event_...
This is at best misleading and imo rather a bug in the documentation.
@All: Thanks for your help :-)
-----Ursprüngliche Nachricht-----
Von: Curt Arnold [mailto:curt.arnld@gmail.com] Im Auftrag von Curt Arnold
Gesendet: Montag, 10. Mai 2010 15:21
An: Log4J Users List
Betreff: Re: AW: Usage of EnhanedPatternLayout
On May 10, 2010, at 5:48 AM, Huber Christian (IT-DIWA) wrote:
> I would use it when I will try to implement the usage of this class, but so far I am trying to understand how those properties should/can be set.
>
I may be off on some nuance, but I believe %properties is a synonym for %x in the same way that %logger is a synonym for %c.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: AW: Usage of EnhanedPatternLayout
Posted by Curt Arnold <ca...@apache.org>.
On May 10, 2010, at 5:48 AM, Huber Christian (IT-DIWA) wrote:
> I would use it when I will try to implement the usage of this class, but so far I am trying to understand how those properties should/can be set.
>
I may be off on some nuance, but I believe %properties is a synonym for %x in the same way that %logger is a synonym for %c.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
AW: Usage of EnhanedPatternLayout
Posted by "Huber Christian (IT-DIWA)" <Ch...@swisslife.de>.
I would use it when I will try to implement the usage of this class, but so far I am trying to understand how those properties should/can be set.
-----Ursprüngliche Nachricht-----
Von: Yair Ogen [mailto:yairogen@gmail.com]
Gesendet: Montag, 10. Mai 2010 11:58
An: Log4J Users List
Betreff: Re: Usage of EnhanedPatternLayout
Are you using log4j-extras?
On Mon, May 10, 2010 at 12:02 PM, Huber Christian (IT-DIWA) < Christian.Huber@swisslife.de> wrote:
> Actually no, NDC and MDC are referenced in the layout by %x and %X i
> would like to use the conversion pattern %properties as it is
> explained in the javadoc of the EnhancedPatternLayout
> http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedP
> atternLayout.html
>
> Setting properties in NDC or MDC can be done by using the static
> methods of the classes. But I cannot see how to define the above mentioned properties.
>
> -----Ursprüngliche Nachricht-----
> Von: Jacob Kjome [mailto:hoju@visi.com]
> Gesendet: Freitag, 7. Mai 2010 16:12
> An: Log4J Users List
> Betreff: Re: Usage of EnhanedPatternLayout
>
> I think NDC and MDC are what you are looking for.
>
> Jake
>
>
> On Fri, 7 May 2010 14:24:21 +0200
> "Huber Christian (IT-DIWA)" <Ch...@swisslife.de> wrote:
> > Hi all,
> >
> > I stumbled across the javadoc (log4j-1.2.14) for the
> >EnhancedPatternLayout and would like to use the properties conversion
> >pattern to pass additional information to the log output.
> >Unfortunately I have not found out how this can be done, I saw that a
> >LoggingEvent can be given a Map with properties during construction
> >but usually you do not instantiate a LoggingEvent but let the Logger
> >take care of it (the documentation even states that it is an internal
> >representation so I would not try to use it directly). On the other
> >hand you cannot pass any properties etc to a Logger or LoggerFactory.
> >So I am kinda stumped
> here what I am missing.
> >
> > Could anyone give me any pointers on this?
> >
> > Thanks, Chris
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Usage of EnhanedPatternLayout
Posted by Yair Ogen <ya...@gmail.com>.
Are you using log4j-extras?
On Mon, May 10, 2010 at 12:02 PM, Huber Christian (IT-DIWA) <
Christian.Huber@swisslife.de> wrote:
> Actually no, NDC and MDC are referenced in the layout by %x and %X i would
> like to use the conversion pattern %properties as it is explained in the
> javadoc of the EnhancedPatternLayout
> http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html
>
> Setting properties in NDC or MDC can be done by using the static methods of
> the classes. But I cannot see how to define the above mentioned properties.
>
> -----Ursprüngliche Nachricht-----
> Von: Jacob Kjome [mailto:hoju@visi.com]
> Gesendet: Freitag, 7. Mai 2010 16:12
> An: Log4J Users List
> Betreff: Re: Usage of EnhanedPatternLayout
>
> I think NDC and MDC are what you are looking for.
>
> Jake
>
>
> On Fri, 7 May 2010 14:24:21 +0200
> "Huber Christian (IT-DIWA)" <Ch...@swisslife.de> wrote:
> > Hi all,
> >
> > I stumbled across the javadoc (log4j-1.2.14) for the
> >EnhancedPatternLayout and would like to use the properties conversion
> >pattern to pass additional information to the log output. Unfortunately
> >I have not found out how this can be done, I saw that a LoggingEvent
> >can be given a Map with properties during construction but usually you
> >do not instantiate a LoggingEvent but let the Logger take care of it
> >(the documentation even states that it is an internal representation so
> >I would not try to use it directly). On the other hand you cannot pass
> >any properties etc to a Logger or LoggerFactory. So I am kinda stumped
> here what I am missing.
> >
> > Could anyone give me any pointers on this?
> >
> > Thanks, Chris
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
AW: Usage of EnhanedPatternLayout
Posted by "Huber Christian (IT-DIWA)" <Ch...@swisslife.de>.
Actually no, NDC and MDC are referenced in the layout by %x and %X i would like to use the conversion pattern %properties as it is explained in the javadoc of the EnhancedPatternLayout http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html
Setting properties in NDC or MDC can be done by using the static methods of the classes. But I cannot see how to define the above mentioned properties.
-----Ursprüngliche Nachricht-----
Von: Jacob Kjome [mailto:hoju@visi.com]
Gesendet: Freitag, 7. Mai 2010 16:12
An: Log4J Users List
Betreff: Re: Usage of EnhanedPatternLayout
I think NDC and MDC are what you are looking for.
Jake
On Fri, 7 May 2010 14:24:21 +0200
"Huber Christian (IT-DIWA)" <Ch...@swisslife.de> wrote:
> Hi all,
>
> I stumbled across the javadoc (log4j-1.2.14) for the
>EnhancedPatternLayout and would like to use the properties conversion
>pattern to pass additional information to the log output. Unfortunately
>I have not found out how this can be done, I saw that a LoggingEvent
>can be given a Map with properties during construction but usually you
>do not instantiate a LoggingEvent but let the Logger take care of it
>(the documentation even states that it is an internal representation so
>I would not try to use it directly). On the other hand you cannot pass
>any properties etc to a Logger or LoggerFactory. So I am kinda stumped here what I am missing.
>
> Could anyone give me any pointers on this?
>
> Thanks, Chris
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Usage of EnhanedPatternLayout
Posted by Jacob Kjome <ho...@visi.com>.
I think NDC and MDC are what you are looking for.
Jake
On Fri, 7 May 2010 14:24:21 +0200
"Huber Christian (IT-DIWA)" <Ch...@swisslife.de> wrote:
> Hi all,
>
> I stumbled across the javadoc (log4j-1.2.14) for the EnhancedPatternLayout
>and would like to use the properties conversion pattern to pass additional
>information to the log output. Unfortunately I have not found out how this
>can be done, I saw that a LoggingEvent can be given a Map with properties
>during construction but usually you do not instantiate a LoggingEvent but let
>the Logger take care of it (the documentation even states that it is an
>internal representation so I would not try to use it directly). On the other
>hand you cannot pass any properties etc to a Logger or LoggerFactory. So I am
>kinda stumped here what I am missing.
>
> Could anyone give me any pointers on this?
>
> Thanks, Chris
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org