Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Logging Question Date: Sat, 31 Dec 2011 22:14:47 -0500 Organization: A noiseless patient Spider Lines: 81 Message-ID: References: <9102298.933.1325372035497.JavaMail.geo-discussion-forums@prj1> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 1 Jan 2012 03:08:59 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="qwFw1g9RsQ6TkML5yezG9A"; logging-data="26157"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nEKsgbgarHqmg3CbdK6n7eYG5xAHh3s8=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20111110 Icedove/3.0.11 In-Reply-To: Cancel-Lock: sha1:LPauOOn9FaRC10RRHzIP6B91dTs= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11048 On 12/31/2011 08:59 PM, Novice wrote: > Lew 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 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" > >> OTOH, perhaps you can take the log file output and post-process it. >> That would depend on the transformation you intend to perform and its >> use case. If those support the approach, you can use Java's standard >> XML tools to do the transformation. > > Which tools are you thinking of? I haven't done much XML stuff in Java. > >> Or you can use XSLT to >> post-process the file. >> > That would actually be my preference. I have a decent XSLT file that > formats my log records just the way I want to see them. I'm just trying > to avoid manually adding in that xsl:spreadsheet line in each log file > after it is written. That's just tedious. > > But post-processing is certainly an option. I could always write an Ant > script to insert that xsl:spreadsheet line in the existing file. That would be fairly ironic, seein's how Ant uses their own custom Formatter for (styled)XML output. I'd have > to run the Ant script each time which would actually be more work than > pasting the extra line in manually.... That's the way it goes sometimes: > the amount of work you have to do to do something elegantly is > substantially more than if you just did something manually like pasting > in a single line. >