Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11049

Re: Logging Question

From Novice <novice@example..com>
Newsgroups comp.lang.java.programmer
Subject Re: Logging Question
Date 2012-01-01 05:44 +0000
Organization Your Company
Message-ID <Xns9FCD791489D5jpnasty@94.75.214.39> (permalink)
References <Xns9FCCA78288290jpnasty@94.75.214.39> <9102298.933.1325372035497.JavaMail.geo-discussion-forums@prj1> <Xns9FCCD5AF3DFF0jpnasty@94.75.214.39> <jdoiob$phd$1@dont-email.me>

Show all headers | View raw


Jeff Higgins <jeff@invalid.invalid> wrote in
news:jdoiob$phd$1@dont-email.me: 

> On 12/31/2011 08:59 PM, Novice wrote:
>> Lew<lewbloch@gmail.com>  wrote in
>> news:9102298.933.1325372035497.JavaMail.geo-discussion-forums@prj1:
>>
>>> Novice wrote:
>>>> I have a question about the standard Java logging.
>>>>
>>>> I am using the Java classes to create an XML log. Is there any way
>>>> that I can insert an extra line in the XML generated by the logging
>>>> classes programmatically? That extra line is NOT a log record, it
>>>> is an<xsl:stylesheet>  tag. I have a specific XSL file that I'd
>>>> like to format the XML with and it would be rather convenient to
>>>> have the program insert that line in the XML file.
>>>
>>> Why do you want to format the XML?
>>>
>> Because it's much easier to read that way :-)
>>
>>>> I've poked around the API and the documentation on logging but
>>>> don't see anything like this. It seems like a simple enough thing
>>>> that I'd like to believe this kind of thing was provided for....
>>>
>>> Simple doesn't mean that a class is designed for it.  Otherwise
>>> there'd only be one class in all of Java that did all simple things.
>>> So obviously the reasoning that it's "simple enough ... that I'd
>>> like to believe this kind of thing was provided for.... [sic]" is
>>> fallacious.  (So is the premise that it's a simple thing, but that
>>> fallacy is irrelevant because even if it were simple it wouldn't
>>> matter.)
>>>
>> Given that the logging classes have the ability to write XML and
>> given that XML may be substantially easier to read if formatted, it
>> seemed reasonable to think that the logging classes might include the
>> capability to specify the stylesheet that might be applied to that
>> XML. I didn't say that they MUST have that capability, just that it
>> seems like the kind of thing that MIGHT be there.
>>
>>> In fact I've never heard of such a thing being built in to
>>> j.u.logging and it would surprise the hell out of me if it were. 
>>> Anyhow I, too, was unable to find anything like that built in to
>>> j.u.logging, probably because it really isn't there.
>>>
>> I could get the effect what I wanted by adding a single line to the
>> getHead method of XMLFormatter. But I'm not sure how to subclass a
>> class that I never invoke directly myself. Where would I put my
>> "CustomizedXMLFormatter" class? In the same package as the rest of
>> the program that uses it?
> 
> Anywhere you care to I suppose. See Handler.setFormatter method and 
> property. See "java+logging+configuration"
> 
Yes! I simply copied XMLFormatter from the Java source file, added one 
line to setHead() to make it add the xsl:stylesheet line, and put the new 
class in the same package as my program. Then I looked up the handler for 
the logger that I had assigned, which was FileHandler, and set its 
formatter to new StyledXMLFormatter(). I ran the program and the log file 
had the desired stylesheet info in it, exactly as I wanted.

I _knew_ I should just be able to subclass XMLFormatter and use a 
modified version of that one method but it seemed harder than that for 
some reason.

Thanks to you - and Lew - for helping me clarify my thoughts.
-- 
Novice

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Logging Question Novice <novice@example..com> - 2011-12-31 21:27 +0000
  Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2011-12-31 17:25 -0500
    Re: Logging Question Novice <novice@example..com> - 2012-01-01 01:46 +0000
  Re: Logging Question Lew <lewbloch@gmail.com> - 2011-12-31 14:53 -0800
    Re: Logging Question Novice <novice@example..com> - 2012-01-01 01:59 +0000
      Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2011-12-31 22:14 -0500
        Re: Logging Question Novice <novice@example..com> - 2012-01-01 05:44 +0000
          Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 07:59 -0500
            Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 08:14 -0500
            Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-01 19:06 -0400
              Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 18:24 -0500
              Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-03 15:33 +0000
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-03 11:21 -0500
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-03 11:35 -0500
                Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-04 14:42 +0000
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-04 11:43 -0500
                Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-04 20:28 -0400
                Re: Logging Question Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-01-05 11:28 +0200
                Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-08 14:08 +0000
                Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-09 19:47 -0400

csiph-web