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 Jitendra Kharche <ji...@geometricsoftware.com> on 2005/04/25 11:25:28 UTC

Writing log in xml format

Hello List,
 
Can I write the log in an xml format using Log4j?
If yes, please provide a simple example configuration or necessary
steps.
 
Regards,
Jitendra

Re: Writing log in xml format

Posted by Hakan Koseoglu <ha...@gmail.com>.
Hi Andy! :)

How many Andy McBrides can there be interested in pushing weird stuff
into jms queues? I wonder...

> Ok, now I'm worried.
> I use a subclass of XMLLayout (see below) which was based on the log4j1.2.9
> implementation.  I've seen that there have been big changes to the
> implementation of XMLLayout since 1.2.9 but thought that all the changes
> were backwards compatible.
> If this is not the case then I have some work to do before I can adopt 1.3
> :-(
Out of curiosity, are you pushing these into Vitria for WTR or to
ITellium backend on POS or was this on VS?

This type of error message should have been SNMP which you've done
already some great work on and as far as I remember we never used it.
Since then I'm trying to see someone interested in SNMP error
reporting...  :(

-- 
Hakan (m1fcj)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Thu, 2005-04-28 at 15:02 -0500, Curt Arnold wrote:
> On Apr 28, 2005, at 1:40 PM, Dave Pawson wrote:
> 
> >
> > I think that means the 'end user' shouldn't have to escape his content?
> > If so I agree.
> > logger.info("One < two"); etc.
> 
> We are thinking alike then.  Your first message had said "Not the 
> applications concern" and " The application should be responsible", I'm 
> guessing that you dropped a NOT from the second sentence.

<grin/> Definition of the application?
I meant the users application, they shouldn't have to worry about it.
The application - log4j - should look after it.

> >
> 
> The encoding is not attribute of the layout, but WriterAppender which 
> FileAppender and others extend. 
Sorry, I didn't know that.
>  The current XMLLayout is unsafe when 
> attached to an WriterAppender that is not "UTF-8" or one of the 
> "UTF-16"'s, however there is no way for the layout to determine or 
> change the encoding the writer.  The default encoding for the existing 
> WriterAppender derived classes should not be changed since existing use 
> with other appenders (PatternLayout) expect that the output encoding to 
> be in the platform default encoding.
That sounds bad.
  Tied to the platform default encoding could mean anything.
  How could they be separated?


> The scenarios that I described can be avoided if the person building 
> the configuration is aware that they need to specify a Unicode encoding 
> on the appender when they use an XMLLayout.
I think that should be mandated.
>   We could make the JavaDoc 
> for XMLLayout much more emphatic that that needs to be done, however 
> that you would get nowhere close to 100% adherence to that 
> recommendation. 
No, but if its clear, the responsibility is clearly on the user of
log4j.  I'm hoping that people will be slowly coming round to an
understanding of i18N as XML usage spreads.
  
>  Since the problem can almost entirely be avoided by 
> use of character entities for non-USASCII characters and the cost would 
> be negligible unless you you were primarily logging in non-European 
> languages in which case the log files would be larger than necessary.  
> If that is really a concern the use of entities could be configured.
If you mean numerical character entities (&#x1234; form) then I agree.
 The base requirement should be for utf-8 encoding.


> XMLLayout only works in terms of Java Strings and chars which are 
> defined as UTF-16 code points.  The problems come when the string is 
> converted to a byte stream or vice-versa. 
I've used the term serialization for that.
>  The UI will take care of 
> converting the keystrokes into characters from log4j perspective it 
> doesn't matter whether a character was generated by someone pressing 
> the "A" key or an 'A' or a '\u0041' in the source file.  In the same 
> way an XML processor is required to treat <foo>A</foo> and 
> <foo>&#x41;</foo> identically.
Yes. But not all users appreciate that task of the parser in those
conversions when read from a file :)
> 
> 
> 
> >
> >>   My feeling is that most configurations
> >> that use XMLLayout are vulnerable to this problem but are either
> >> running on platforms where the default encoding is UTF-8 or have not
> >> encountered messages containing characters between \u0080 and \u00FF.
> >   I.e. its not really predictable? Hence make it clear, hence
> > predictable and hence a solid chain can be designed, input to output,
> > based on utf-8|16
> 
> Can't do that.  Existing users of the other layouts depend on the 
> encoding being in the platform default encoding.
Hence the question of how to isolate the XMLLayout from those others.


> 
> As said previously, the XMLLayout cannot easily affect the encoding 
> used by the writer that it is attached to.

Hence they should work as a pair, without conflicting
requirements placed on them.


regards DaveP


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Curt Arnold <ca...@apache.org>.
On Apr 28, 2005, at 1:40 PM, Dave Pawson wrote:

>
> I think that means the 'end user' shouldn't have to escape his content?
> If so I agree.
> logger.info("One < two"); etc.

We are thinking alike then.  Your first message had said "Not the 
applications concern" and " The application should be responsible", I'm 
guessing that you dropped a NOT from the second sentence.
>
>>
>  DP said.
>>> I'd say (contra to some 'laws' :-) that log4j make no assumptions 
>>> about
>>> downstream usage.
>>> produce (and declare) utf-8 encoding. No more. it's impossible to
>>> predict what people will do with a file?
>>
>> There are two distinct issues here that I jumbled together.
>>
>> If the current XMLLayout is used and the encoding of the appender is
>> not set to UTF-8 or one of the UTF-16's, the resulting file may be
>> non-wellformed or lose information.
> Yes, KISS Principle perhaps? utf-8 or 16 as the two setup options?
>

The encoding is not attribute of the layout, but WriterAppender which 
FileAppender and others extend.  The current XMLLayout is unsafe when 
attached to an WriterAppender that is not "UTF-8" or one of the 
"UTF-16"'s, however there is no way for the layout to determine or 
change the encoding the writer.  The default encoding for the existing 
WriterAppender derived classes should not be changed since existing use 
with other appenders (PatternLayout) expect that the output encoding to 
be in the platform default encoding.


>>  For example, the default encoding
>> on Windows platforms is the current Windows code page (for example,
>> Cp1252 for Western European langauges).  Unless the user explicitly
>> overrides the default encoding on a file appender, then generated XML
>> file will become corrupt if any non-ASCII character is output.
> Which is why the output needs to be Unicode based?
>

The scenarios that I described can be avoided if the person building 
the configuration is aware that they need to specify a Unicode encoding 
on the appender when they use an XMLLayout.  We could make the JavaDoc 
for XMLLayout much more emphatic that that needs to be done, however 
that you would get nowhere close to 100% adherence to that 
recommendation.  Since the problem can almost entirely be avoided by 
use of character entities for non-USASCII characters and the cost would 
be negligible unless you you were primarily logging in non-European 
languages in which case the log files would be larger than necessary.  
If that is really a concern the use of entities could be configured.


>>   log4j does not attempt to prevent or detect a
>> mismatch between the encoding required by the XMLLayout and the
>> encoding in use by the Writer.
> Are you talking about the XML serialization here?

Hopefully the other responses have clarified the issue for you.  It 
would be talking about "XML Serialization" as the combination of the 
WriterAppender and XMLLayout would essentially convert an XML document 
into a stream of bytes, however it would not be involving a general 
purpose XML serializer.



>
>>  If the XMLLayout represented all
>> characters >= \u0080 as character entities, the catastrophic effects 
>> of
>> a mismatch would be reduced.
> It would (or could) still be a guess, if the user uses funny keyboard
> shortcuts, explicit European keys etc to produce the messages.
> If the mandate is that any text passed to an XMLLayout output must
> be in utf-8 then the XML path becomes clear, and no guesses are needed.
> If the user messes up, they can expect funny glyphs in their output.
>   I think that's a subset of the expectation of a majority of XML
> applications.

XMLLayout only works in terms of Java Strings and chars which are 
defined as UTF-16 code points.  The problems come when the string is 
converted to a byte stream or vice-versa.  The UI will take care of 
converting the keystrokes into characters from log4j perspective it 
doesn't matter whether a character was generated by someone pressing 
the "A" key or an 'A' or a '\u0041' in the source file.  In the same 
way an XML processor is required to treat <foo>A</foo> and 
<foo>&#x41;</foo> identically.



>
>>   My feeling is that most configurations
>> that use XMLLayout are vulnerable to this problem but are either
>> running on platforms where the default encoding is UTF-8 or have not
>> encountered messages containing characters between \u0080 and \u00FF.
>   I.e. its not really predictable? Hence make it clear, hence
> predictable and hence a solid chain can be designed, input to output,
> based on utf-8|16

Can't do that.  Existing users of the other layouts depend on the 
encoding being in the platform default encoding.


>
>> Since the character and the corresponding character entity are 
>> required
>> to be treated identically by an XML processor, using a character 
>> entity
>> seems to have no downside other than a some increase in file size and
>> maybe some impact on performance.
> Who would you expect to do the conversion from bullet to &#x2022;?
> The author, or the XMLLayout code?
>   That's where I think it becomes too cumbersome?

It would be inside of XMLLayout.

>>
>> The second issue is that users may want to attempt to view an XML log
>> with a non-XML aware tool (Notepad, tail, etc) which could assume the
>> current platform encoding instead UTF-8.
>   That's an assumption, and the source of lots of trouble IMHO.
> If a user selects XML output, they should be able to read the encoding
> statement in the declaration and understand what it means.
>
>
>>  If non-USASCII characters
>> were expressed as character entities, these tools could still be used
>> without potentially misinterpreting or corrupting the data.
>   No XML application is required to output ncr's athough they may
> if serializing in an encoding which doesn't support that character.
> Hence my simpler proposal above.

As said previously, the XMLLayout cannot easily affect the encoding 
used by the writer that it is attached to.

>>
>> Just in the last few hours there was a bug request filed to add a
>> header/footer to the rolling file appender which would be very similar
>> to that request.
>
> If it's doable, the xml declaration, encoding, and document element
> are a valuable addition IMHO.
>
> regards DaveP
>
>
>
> ---------------------------------------------------------------------
> 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: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Wed, 2005-04-27 at 15:14 -0500, Curt Arnold wrote:
> On Apr 27, 2005, at 1:22 PM, Dave Pawson wrote:
> 
> > On Wed, 2005-04-27 at 13:03 -0500, Curt Arnold wrote:
> >> I'm not fond of the CDATA sections either.   Since the XMLLayout is 
> >> not
> >> aware of the encoding of the writer, it does not know when to create
> >> character entities.
> > Not the applications concern is my response.
> >   The application should be responsible for escaping those characters
> >   that XML has declared that it doesn't like (&lt; and &amp;....
> > OK and [[ => [&#x5A;
> > Anything else the author should transpose into numerical character
> > entities.
> >
> 
> The first two sentences appear contradict each other.   The body of 
> code calling logger.info() et al should not escape its messages so they 
> are safe for a naive XML serialization. 

I think that means the 'end user' shouldn't have to escape his content?
If so I agree. 
logger.info("One < two"); etc.

>  For example, the message may 
> be routed to both a ConsoleAppender with a non-XML layout where a 
> literal '<' would be appropriate and FileAppender with an XML layout 
> where &lt; would be appropriate.

I'd suggest that it is the xmllayout that escapes the three characters
needing to be escaped. That avoids the cdata sections.

I hope that isn't contradictory?

> 
 DP said.
> > I'd say (contra to some 'laws' :-) that log4j make no assumptions about
> > downstream usage.
> > produce (and declare) utf-8 encoding. No more. it's impossible to
> > predict what people will do with a file?
> 
> There are two distinct issues here that I jumbled together.
> 
> If the current XMLLayout is used and the encoding of the appender is 
> not set to UTF-8 or one of the UTF-16's, the resulting file may be 
> non-wellformed or lose information. 
Yes, KISS Principle perhaps? utf-8 or 16 as the two setup options?

>  For example, the default encoding 
> on Windows platforms is the current Windows code page (for example, 
> Cp1252 for Western European langauges).  Unless the user explicitly 
> overrides the default encoding on a file appender, then generated XML 
> file will become corrupt if any non-ASCII character is output.
Which is why the output needs to be Unicode based?

>   log4j does not attempt to prevent or detect a 
> mismatch between the encoding required by the XMLLayout and the 
> encoding in use by the Writer. 
Are you talking about the XML serialization here?

>  If the XMLLayout represented all 
> characters >= \u0080 as character entities, the catastrophic effects of 
> a mismatch would be reduced.
It would (or could) still be a guess, if the user uses funny keyboard
shortcuts, explicit European keys etc to produce the messages.
If the mandate is that any text passed to an XMLLayout output must
be in utf-8 then the XML path becomes clear, and no guesses are needed.
If the user messes up, they can expect funny glyphs in their output.
  I think that's a subset of the expectation of a majority of XML
applications.

>   My feeling is that most configurations 
> that use XMLLayout are vulnerable to this problem but are either 
> running on platforms where the default encoding is UTF-8 or have not 
> encountered messages containing characters between \u0080 and \u00FF.  
  I.e. its not really predictable? Hence make it clear, hence
predictable and hence a solid chain can be designed, input to output,
based on utf-8|16

> Since the character and the corresponding character entity are required 
> to be treated identically by an XML processor, using a character entity 
> seems to have no downside other than a some increase in file size and 
> maybe some impact on performance.
Who would you expect to do the conversion from bullet to &#x2022;?
The author, or the XMLLayout code?
  That's where I think it becomes too cumbersome?
> 
> The second issue is that users may want to attempt to view an XML log 
> with a non-XML aware tool (Notepad, tail, etc) which could assume the 
> current platform encoding instead UTF-8. 
  That's an assumption, and the source of lots of trouble IMHO.
If a user selects XML output, they should be able to read the encoding
statement in the declaration and understand what it means.


>  If non-USASCII characters 
> were expressed as character entities, these tools could still be used 
> without potentially misinterpreting or corrupting the data.
  No XML application is required to output ncr's athough they may
if serializing in an encoding which doesn't support that character.
Hence my simpler proposal above.



> 
> Just in the last few hours there was a bug request filed to add a 
> header/footer to the rolling file appender which would be very similar 
> to that request.

If it's doable, the xml declaration, encoding, and document element
are a valuable addition IMHO.

regards DaveP



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Curt Arnold <ca...@houston.rr.com>.
On Apr 27, 2005, at 1:22 PM, Dave Pawson wrote:

> On Wed, 2005-04-27 at 13:03 -0500, Curt Arnold wrote:
>> I'm not fond of the CDATA sections either.   Since the XMLLayout is 
>> not
>> aware of the encoding of the writer, it does not know when to create
>> character entities.
> Not the applications concern is my response.
>   The application should be responsible for escaping those characters
>   that XML has declared that it doesn't like (&lt; and &amp;....
> OK and [[ => [&#x5A;
> Anything else the author should transpose into numerical character
> entities.
>

The first two sentences appear contradict each other.   The body of 
code calling logger.info() et al should not escape its messages so they 
are safe for a naive XML serialization.  For example, the message may 
be routed to both a ConsoleAppender with a non-XML layout where a 
literal '<' would be appropriate and FileAppender with an XML layout 
where &lt; would be appropriate.


>
>>   My preference would be to use character entities
>> for markup characters or any non-USASCII character which would
>> eliminate the need for the CDATA sections and would allow the log to
>> still be readable in case an editor assumes ISO-8859-1 and the 
>> document
>> is UTF-8 or vice-versa.
> I'd say (contra to some 'laws' :-) that log4j make no assumptions about
> downstream usage.
> produce (and declare) utf-8 encoding. No more. it's impossible to
> predict what people will do with a file?

There are two distinct issues here that I jumbled together.

If the current XMLLayout is used and the encoding of the appender is 
not set to UTF-8 or one of the UTF-16's, the resulting file may be 
non-wellformed or lose information.  For example, the default encoding 
on Windows platforms is the current Windows code page (for example, 
Cp1252 for Western European langauges).  Unless the user explicitly 
overrides the default encoding on a file appender, then generated XML 
file will become corrupt if any non-ASCII character is output.  If the 
character is > \u00FF, the character will be replaced with a 
substitution character '?'.  If the character is > \u0080 and \u00FF 
inclusive, the code will be output but will likely result in an illegal 
UTF-8 sequence which XML parsers are required to treat as an 
unrecoverable error.  log4j does not attempt to prevent or detect a 
mismatch between the encoding required by the XMLLayout and the 
encoding in use by the Writer.  If the XMLLayout represented all 
characters >= \u0080 as character entities, the catastrophic effects of 
a mismatch would be reduced.  My feeling is that most configurations 
that use XMLLayout are vulnerable to this problem but are either 
running on platforms where the default encoding is UTF-8 or have not 
encountered messages containing characters between \u0080 and \u00FF.  
Since the character and the corresponding character entity are required 
to be treated identically by an XML processor, using a character entity 
seems to have no downside other than a some increase in file size and 
maybe some impact on performance.

The second issue is that users may want to attempt to view an XML log 
with a non-XML aware tool (Notepad, tail, etc) which could assume the 
current platform encoding instead UTF-8.  If non-USASCII characters 
were expressed as character entities, these tools could still be used 
without potentially misinterpreting or corrupting the data.

>
>>  There is a decent likelihood for XMLLayout to
>> change before final release of log4j 1.3, so it may be better to avoid
>> subclassing it since it really doesn't appear to be designed for
>> extension and not that hard to duplicate.  I think it should have been
>> marked final, but then I think that about a lot of things.
>
> Ah! Hope for me yet!
>
>
>>>
>>> Is there a way I can .... (I'm looking for help here)
>>>   Ask log4j to keep all the stuff I can set via the text properties
>>> file, and then make it available via the api for the xml formatter?
>>
>> What is "all the stuff I can set via the text properties"?  Anything
>> you can place in the MDC, NDC or properties should be present in the
>> generated XML.
> That's a comment I have on 'the book'.
> Both those terms are used, without explanation.
> Am I supposed to know what they mean?
> I don't.
>


NDC: Nested diagnostic context, see 
http://logging.apache.org/log4j/docs/manual.html
MDC: Mapped diagnostic context, 
http://logging.apache.org/log4j/docs/api/org/apache/log4j/MDC.html

The appender properties are something new in log4j 1.3 that I really 
haven't played with.


>>>
>>
>> A log file can be appended to by several invocations of an application
>> each of which appends to the running log.  If each invocation wrote
>> <log4j:log> and </log4j:log> at its start up and termination, you 
>> would
>> still have the problem of multiple document elements.
>>
>> A possible solution is to use a o.a.l.rolling.RollingFileAppender with
>> a RollingPolicy that instead of just renaming the file on a roll, it
>> would add the outer document element.
>
> Hence it was a request :-)
>
> Someone knows when this logger starts.... (the timing thingy perhaps)
> That's the class I'm talking about.
>

Just in the last few hours there was a bug request filed to add a 
header/footer to the rolling file appender which would be very similar 
to that request.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Wed, 2005-04-27 at 13:03 -0500, Curt Arnold wrote:
> I'm not fond of the CDATA sections either.   Since the XMLLayout is not 
> aware of the encoding of the writer, it does not know when to create 
> character entities.
Not the applications concern is my response.
  The application should be responsible for escaping those characters
  that XML has declared that it doesn't like (&lt; and &amp;....
OK and [[ => [&#x5A;
Anything else the author should transpose into numerical character
entities.


>   My preference would be to use character entities 
> for markup characters or any non-USASCII character which would 
> eliminate the need for the CDATA sections and would allow the log to 
> still be readable in case an editor assumes ISO-8859-1 and the document 
> is UTF-8 or vice-versa. 
I'd say (contra to some 'laws' :-) that log4j make no assumptions about
downstream usage.
produce (and declare) utf-8 encoding. No more. it's impossible to 
predict what people will do with a file?


>  There is a decent likelihood for XMLLayout to 
> change before final release of log4j 1.3, so it may be better to avoid 
> subclassing it since it really doesn't appear to be designed for 
> extension and not that hard to duplicate.  I think it should have been 
> marked final, but then I think that about a lot of things.

Ah! Hope for me yet!
  

> >
> > Is there a way I can .... (I'm looking for help here)
> >   Ask log4j to keep all the stuff I can set via the text properties
> > file, and then make it available via the api for the xml formatter?
> 
> What is "all the stuff I can set via the text properties"?  Anything 
> you can place in the MDC, NDC or properties should be present in the 
> generated XML. 
That's a comment I have on 'the book'.
Both those terms are used, without explanation.
Am I supposed to know what they mean?
I don't.

> >
> 
> A log file can be appended to by several invocations of an application 
> each of which appends to the running log.  If each invocation wrote 
> <log4j:log> and </log4j:log> at its start up and termination, you would 
> still have the problem of multiple document elements.
> 
> A possible solution is to use a o.a.l.rolling.RollingFileAppender with 
> a RollingPolicy that instead of just renaming the file on a roll, it 
> would add the outer document element.

Hence it was a request :-)

Someone knows when this logger starts.... (the timing thingy perhaps)
That's the class I'm talking about.

regards DaveP




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Curt Arnold <ca...@apache.org>.
On Apr 27, 2005, at 3:52 PM, Andy McBride wrote:

> On Wed, 27 Apr 2005 13:03:02 -0500
>  Curt Arnold <ca...@houston.rr.com> wrote:
> <snip>
>
>> There is a decent likelihood for XMLLayout to change
>> before final release of log4j 1.3, so it may be better to
>> avoid subclassing it since it really doesn't appear to be
>> designed for extension and not that hard to duplicate.  I
>> think it should have been marked final, but then I think
>> that about a lot of things.
>
> Ok, now I'm worried.
> I use a subclass of XMLLayout (see below) which was based on the 
> log4j1.2.9
> implementation.  I've seen that there have been big changes to the
> implementation of XMLLayout since 1.2.9 but thought that all the 
> changes
> were backwards compatible.
> If this is not the case then I have some work to do before I can adopt 
> 1.3
> :-(
>
> If the actual xml output or the log4j.dtd has changed/will change in an
> incompatible way it will prevent going to 1.3 as I have 3rd party apps 
> which
> have been developed to parse the output from my custom layout which
> validates against the current log4j.dtd.
>

Thanks for the info and sorry for the scare.  I would not expect any 
changes that should adversely affect API or XML compatibility and would 
raise any potential issues before proceeding.

In this case, David Pawson's was undertaking an custom layout that 
would reuse very little of XMLLayout and it would be prudent for him 
not to extend XMLLayout if it is a total or near total replacement.  
For example, if the enhancements to XMLLayout allowed specifying 
whether CDATASections were used, his extension of XMLLayout would 
inherit that configuration parameter but since he would be totally 
replacing XMLLayout.format, it would have no effect.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Writing log in xml format

Posted by Andy McBride <an...@dsl.pipex.com>.
On Wed, 27 Apr 2005 13:03:02 -0500
 Curt Arnold <ca...@houston.rr.com> wrote:
<snip>

> There is a decent likelihood for XMLLayout to change 
>before final release of log4j 1.3, so it may be better to 
>avoid subclassing it since it really doesn't appear to be 
>designed for extension and not that hard to duplicate.  I 
>think it should have been marked final, but then I think 
>that about a lot of things.

Ok, now I'm worried.  
I use a subclass of XMLLayout (see below) which was based on the log4j1.2.9
implementation.  I've seen that there have been big changes to the
implementation of XMLLayout since 1.2.9 but thought that all the changes
were backwards compatible.  
If this is not the case then I have some work to do before I can adopt 1.3
:-(

If the actual xml output or the log4j.dtd has changed/will change in an
incompatible way it will prevent going to 1.3 as I have 3rd party apps which
have been developed to parse the output from my custom layout which
validates against the current log4j.dtd.  

>
>>
>> (And the next request will be...
>>   Can I ask some module who knows, to output
>>    <log4j:log>
>> before my application starts writing and
>>
>>    </log4j:log>
>> just before finishing :-)
>>
>
>A log file can be appended to by several invocations of 
>an application each of which appends to the running log. 
> If each invocation wrote <log4j:log> and </log4j:log> at 
>its start up and termination, you would still have the 
>problem of multiple document elements.
>
>A possible solution is to use a 
>o.a.l.rolling.RollingFileAppender with a RollingPolicy 
>that instead of just renaming the file on a roll, it 
>would add the outer document element.
>

My requirement was to be able to publish 'fatal' log messages onto a JMS
queue for consumption by a third party 'Error reporting system'.  As this
system is non-java, I decided to implement this by writing a custom JMS
appender which uses a javax.jms.TextMessage rather than serializing the log
event.  I then wrote the following XMLLayout subclass to render each message
as a complete xml document rather than a fragment:

public class XMLDocumentLayout extends XMLLayout
{
  public String getHeader()
  {
    return "<?xml version=\"1.0\" ?>\n" 
            + "<!DOCTYPE log4j:eventSet SYSTEM \"log4j.dtd\">\n" 
            + "<log4j:eventSet version=\"1.2\"
xmlns:log4j=\"http://jakarta.apache.org/log4j/\">";
  }

  public String getFooter()
  {
    return "</log4j:eventSet>";
  }

}

This allows each message to be checked to be well-formed and validated
against the log4j.dtd at the remote end.  It is then parsed and actioned by
the fault reporting system.  

I thought the log4j.dtd was quite stable, have I made a booboo going down
this route? 

Regards

Andy




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Curt Arnold <ca...@houston.rr.com>.
On Apr 27, 2005, at 12:21 PM, Dave Pawson wrote:
>>
>> The XMLLayout works fine for me although it is not the most human 
>> readable
>> xml!
> Errr yes. I'm taking your advice and subclassing that. First thing will
> be to remove the CDATA sections!
>
>

I'm not fond of the CDATA sections either.   Since the XMLLayout is not 
aware of the encoding of the writer, it does not know when to create 
character entities.  My preference would be to use character entities 
for markup characters or any non-USASCII character which would 
eliminate the need for the CDATA sections and would allow the log to 
still be readable in case an editor assumes ISO-8859-1 and the document 
is UTF-8 or vice-versa.  There is a decent likelihood for XMLLayout to 
change before final release of log4j 1.3, so it may be better to avoid 
subclassing it since it really doesn't appear to be designed for 
extension and not that hard to duplicate.  I think it should have been 
marked final, but then I think that about a lot of things.


>> It works because its format complies with the dtd (contained in the
>> log4.jar in org\apache\log4j\xml\log4j.dtd) and therefore I can 
>> validate it
>> and transform it into any format I like.
>
> Exactly. Filter it, select just certain entries. Its the (slower)
> version of reading text output from log4j.
>
> Is there a way I can .... (I'm looking for help here)
>   Ask log4j to keep all the stuff I can set via the text properties
> file, and then make it available via the api for the xml formatter?

What is "all the stuff I can set via the text properties"?  Anything 
you can place in the MDC, NDC or properties should be present in the 
generated XML.  If you want to discuss a configurable template, then 
I'd start looking at adding a new layout that drives an available XSLT 
implementation.



>
> (And the next request will be...
>   Can I ask some module who knows, to output
>    <log4j:log>
> before my application starts writing and
>
>    </log4j:log>
> just before finishing :-)
>

A log file can be appended to by several invocations of an application 
each of which appends to the running log.  If each invocation wrote 
<log4j:log> and </log4j:log> at its start up and termination, you would 
still have the problem of multiple document elements.

A possible solution is to use a o.a.l.rolling.RollingFileAppender with 
a RollingPolicy that instead of just renaming the file on a roll, it 
would add the outer document element.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Tue, 2005-04-26 at 21:31 +0100, Andy McBride wrote:
> Hi Dave, 
> 
> Some appenders allow you specify a 'layout' class to be used which is
> responsible for rendering/formatting each log message.  Examples include
> HTMLLayout, XMLLayout and the PatternLayout you've been using.  
> 
> The main advantage of the PatternLayout is that it lets you configure the
> ConversionPattern property to change the format of the log messages. 
> Other layouts render to a fixed format e.g. XMLLayout, SimpleLayout,
> TTCLayout etc.  
> 
> What is the motivation for requiring xml output?
www.dpawson.co.uk/xsl 

I have some nice tools that let me play with XML quite happily.
  I do it all day everyday. 
I.e. If I have data, I can analyze it far more easily if its in XML.

>  If it is so that log files
> can be parsed/transformed remotely then surely you would want the format to
> be fixed i.e. complying with some dtd/xsd.  
Errr yes, and no.
  If I wrote (the log entries) then I can write templates (in xslt) to
match them, so yes regular, not necessarily a DTD to go with it.


> 
> The XMLLayout works fine for me although it is not the most human readable
> xml! 
Errr yes. I'm taking your advice and subclassing that. First thing will
be to remove the CDATA sections!


> It works because its format complies with the dtd (contained in the
> log4.jar in org\apache\log4j\xml\log4j.dtd) and therefore I can validate it
> and transform it into any format I like.  

Exactly. Filter it, select just certain entries. Its the (slower)
version of reading text output from log4j.

Is there a way I can .... (I'm looking for help here)
  Ask log4j to keep all the stuff I can set via the text properties
file, and then make it available via the api for the xml formatter?

(And the next request will be...
  Can I ask some module who knows, to output
   <log4j:log>
before my application starts writing and 

   </log4j:log>
just before finishing :-)

Using external parsed entities is plain hard work
when All I want to do is select X Y and Z from a log.

It can be done in XSLT 2.0, but its messy.

regards DaveP


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Writing log in xml format

Posted by Andy McBride <an...@dsl.pipex.com>.
Hi Dave, 

Some appenders allow you specify a 'layout' class to be used which is
responsible for rendering/formatting each log message.  Examples include
HTMLLayout, XMLLayout and the PatternLayout you've been using.  

The main advantage of the PatternLayout is that it lets you configure the
ConversionPattern property to change the format of the log messages. 
Other layouts render to a fixed format e.g. XMLLayout, SimpleLayout,
TTCLayout etc.  

What is the motivation for requiring xml output? If it is so that log files
can be parsed/transformed remotely then surely you would want the format to
be fixed i.e. complying with some dtd/xsd.  

The XMLLayout works fine for me although it is not the most human readable
xml! It works because its format complies with the dtd (contained in the
log4.jar in org\apache\log4j\xml\log4j.dtd) and therefore I can validate it
and transform it into any format I like.  

Hope this helps.

Regards

Andy 

> -----Original Message-----
> From: Dave Pawson [mailto:davep@dpawson.co.uk]
> Sent: 26 April 2005 17:18
> To: andy.mcbride@dsl.pipex.com
> Cc: 'Log4J Users List'
> Subject: RE: Writing log in xml format
> 
> On Mon, 2005-04-25 at 21:39 +0100, Andy McBride wrote:
> > Dave,
> >
> > Are you referring to:
> > http://marc.theaimsgroup.com/?l=log4j-user&m=111401761531451&w=2
> >
> > If so it appears that you are trying to use the PatternLayout class to
> > render a custom format xml document?
> 
> Yes, I've a nasty habit of using XML tools on things like this :-)
> >
> > The XMLLayout class pointed out by Hakan, renders log events as xml
> > conforming to the log4j.dtd.
> .... I thought that was for the configuration file, not the output
> of the logger.
>   Now I am confused.
> >  Use of this does not require you to have xml
> > markup in the config file (.properties or.xml) as its format is fixed
> 
> (I'm less keen on that, I like the configurability of log4j :-)
> 
> >
> > If I wanted a custom xml representation of log events, I would consider
> > subclassing XMLLayout and overriding the format(Writer output,
> LoggingEvent
> > event) method, or do you have other requirements?
> 
> .... I don't know yet Andy, since I haven't come across a way of
> getting XML output from log4j.
>  (and I'm having trouble parsing the above sentence! I can hack up
>   tomcat pages, java tools, but that sounds like hard sums!
> http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/XMLLayout.ht
> ml
> 
> Is that it? (Note that the link to the log4j.dtd is 404)
> How do I select XML output....
>   I'll go do some digging.
> 
> Thanks Andy.
> 
> regards DaveP
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Mon, 2005-04-25 at 21:39 +0100, Andy McBride wrote:
> Dave, 
> 
> Are you referring to: 
> http://marc.theaimsgroup.com/?l=log4j-user&m=111401761531451&w=2
> 
> If so it appears that you are trying to use the PatternLayout class to
> render a custom format xml document?

Yes, I've a nasty habit of using XML tools on things like this :-)
> 
> The XMLLayout class pointed out by Hakan, renders log events as xml
> conforming to the log4j.dtd. 
.... I thought that was for the configuration file, not the output
of the logger.
  Now I am confused.
>  Use of this does not require you to have xml
> markup in the config file (.properties or.xml) as its format is fixed 

(I'm less keen on that, I like the configurability of log4j :-)

> 
> If I wanted a custom xml representation of log events, I would consider
> subclassing XMLLayout and overriding the format(Writer output, LoggingEvent
> event) method, or do you have other requirements?

.... I don't know yet Andy, since I haven't come across a way of
getting XML output from log4j.
 (and I'm having trouble parsing the above sentence! I can hack up
  tomcat pages, java tools, but that sounds like hard sums! 
http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/XMLLayout.html

Is that it? (Note that the link to the log4j.dtd is 404)
How do I select XML output....
  I'll go do some digging.

Thanks Andy.

regards DaveP





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Mon, 2005-04-25 at 21:39 +0100, Andy McBride wrote:
> 
> The XMLLayout class pointed out by Hakan, renders log events as xml
> conforming to the log4j.dtd.  Use of this does not require you to have xml
> markup in the config file (.properties or.xml) as its format is fixed 

<log4j:event logger="chapter3.MyApp2" timestamp="1114535229055"
level="INFO" thread="main">
<log4j:message><![CDATA[Did it again!]]></log4j:message>
</log4j:event>  format.

Is there no way to add to this please?

regards DaveP




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


RE: Writing log in xml format

Posted by Andy McBride <an...@dsl.pipex.com>.
Dave, 

Are you referring to: 
http://marc.theaimsgroup.com/?l=log4j-user&m=111401761531451&w=2

If so it appears that you are trying to use the PatternLayout class to
render a custom format xml document?

The XMLLayout class pointed out by Hakan, renders log events as xml
conforming to the log4j.dtd.  Use of this does not require you to have xml
markup in the config file (.properties or.xml) as its format is fixed 

If I wanted a custom xml representation of log events, I would consider
subclassing XMLLayout and overriding the format(Writer output, LoggingEvent
event) method, or do you have other requirements?

Regards

Andy 





> -----Original Message-----
> From: Dave Pawson [mailto:davep@dpawson.co.uk]
> Sent: 25 April 2005 17:34
> To: Hakan Koseoglu
> Cc: Log4J Users List
> Subject: Re: Writing log in xml format
> 
> On Mon, 2005-04-25 at 12:35 +0100, Hakan Koseoglu wrote:
> > > Can I write the log in an xml format using Log4j?
> > > If yes, please provide a simple example configuration or necessary
> > > steps.
> > You can always use org.apache.log4j.xml.XMLLayout.
> 
> Except that an xml file can't have xml markup in an attribute value.
> The point I made a few days ago.
> 
> regards DaveP
> 
> 
> ---------------------------------------------------------------------
> 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: Writing log in xml format

Posted by Dave Pawson <da...@dpawson.co.uk>.
On Mon, 2005-04-25 at 12:35 +0100, Hakan Koseoglu wrote:
> > Can I write the log in an xml format using Log4j?
> > If yes, please provide a simple example configuration or necessary
> > steps.
> You can always use org.apache.log4j.xml.XMLLayout.

Except that an xml file can't have xml markup in an attribute value.
The point I made a few days ago.

regards DaveP


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Writing log in xml format

Posted by Hakan Koseoglu <ha...@gmail.com>.
> Can I write the log in an xml format using Log4j?
> If yes, please provide a simple example configuration or necessary
> steps.
You can always use org.apache.log4j.xml.XMLLayout.
Configure it in your log4j.properties/xml file like
logj.appender.aaa.logfile.layout=org.apache.log4j.xml.XMLLayout.

-- 
Hakan (m1fcj)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org