Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12844
| Date | 2012-03-10 12:08 -0500 |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: SimpleFormatter Question |
| References | <XnsA011D2474C732jpnasty@94.75.214.39> <4f5ab90d$0$289$14726298@news.sunsite.dk> <XnsA011F1BB1A949jpnasty@94.75.214.39> <XnsA011F3BCFD12Ajpnasty@94.75.214.39> |
| Message-ID | <4f5b8ab1$0$290$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
On 3/9/2012 11:57 PM, Novice wrote: > Novice<novice@example..com> wrote in news:XnsA011F1BB1A949jpnasty@ > 94.75.214.39: > >> Arne Vajhøj<arne@vajhoej.dk> wrote in >> news:4f5ab90d$0$289$14726298@news.sunsite.dk: >> >>> On 3/9/2012 8:40 PM, Novice wrote: >>>> I'm experimenting with java.util.logging.SimpleFormatter and I've run >>>> into a problem. >>>> >>>> The API >>>> > (http://docs.oracle.com/javase/7/docs/api/java/util/logging/SimpleForm >>>> att er.html) says that you can control the format of a simple log via >>>> the java.util.logging.SimpleFormatter.format property; a bunch of >>>> variables are available as the value of the property. I put this >>>> value, copied right out of the API, in my logging.properties: >>>> >>>> java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n" >>>> >>>> This is supposed to yield a message that looks like this: >>>> >>>> WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011] >>>> >>>> When I run my program though, the output looks like this: >>>> >>>> 9-Mar-2012 6:09:32 PM com.novice.common.LocalizationUtils >>>> getResources SEVERE: The base name cannot be null. >>>> >>>> In other words, the format I've specified is completely ignored. >>>> >>>> What's the trick to make the program use the format I've specified? >>>> I'm confident that the logging.properties file I've specified in my >>>> VM argument is being used because it is naming my log file correctly. >>>> I'm having trouble thinking of any other reason why this isn't >>>> working. Here is my config file with all the comments stripped out. >>>> >>>> > ====================================================================== >>>> == handlers= java.util.logging.FileHandler, >>>> java.util.logging.ConsoleHandler .level= ALL >>>> java.util.logging.FileHandler.pattern = %h/Foo%u.log >>>> java.util.logging.FileHandler.limit = 50000 >>>> java.util.logging.FileHandler.count = 1 >>>> java.util.logging.FileHandler.formatter = >>>> java.util.logging.SimpleFormatter >>>> java.util.logging.SimpleFormatter.format = "%4$s: %5$s [%1$tc]%n" >>>> java.util.logging.FileHandler.level = ALL >>>> >>>> java.util.logging.ConsoleHandler.level = INFO >>>> java.util.logging.ConsoleHandler.formatter = >>>> java.util.logging.SimpleFormatter >>>> >>>> com.novice.foo.level = ALL >>>> java.level = WARNING >>>> sun.level = WARNING >>>> javax.level = WARNING >>>> > ====================================================================== >>>> == >>>> >>>> I can't see anything in the API that explains this and Google may be >>>> my friend but it isn't helping me sort this out. >>> >>> Are you using Java 7? >>> >>> The docs are for Java 7 and that property does not seem to >>> work for Java 6. >>> >> I think you've solved it! >> >> I have both Java 6 and 7 in Eclipse but this particular project is > using >> Java 6. I've just started using the Java 7 API though. I just assumed >> that what I was seeing in the Java 7 API had been there for the last > few >> versions of Java but I didn't verify that. It seems I've stumbled on a >> feature new to Java 7.... >> >> In that case, my problem is easily solved: just point the project to > the >> Java 7 compiler. >> >> Thanks Arne! I don't think I would have found that problem on my own > any >> time soon! >> > > One followup question. When I tried this in my logging.properties: > > java.util.logging.SimpleFormatter.format = "%4$s: %5$s [%1$tc]%n" > > The log messages included quotes that weren't found in the result > predicted by the SimpleFormatter documentation. When I removed the quotes > from the line I've just quoted, the messages came out the way they were > supposed to. AH - I also fixed that before I tried with Java 7. But as it did not make a difference in itself, then I did not think it was necessary. > In other words, it appears that the quotes shown in the Javadoc don't > belong there. Should I be filing a Bugzilla for that so that Oracle can > fix the documentation? Or is there a different procedure to follow? > > Of course, someone may have already filed a report for this small error; > I haven't checked yet. And maybe this error is so small and obvious that > anyone would figure it out as quickly as I did. If it comes so far then I think a Java developer should become suspicious about the quotes and try without them. But the docs should obviously be correct. Just file a bug and let Oracle look for duplicates. Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
SimpleFormatter Question Novice <novice@example..com> - 2012-03-10 01:40 +0000
Re: SimpleFormatter Question Arne Vajhøj <arne@vajhoej.dk> - 2012-03-09 21:14 -0500
Re: SimpleFormatter Question Novice <novice@example..com> - 2012-03-10 04:45 +0000
Re: SimpleFormatter Question Novice <novice@example..com> - 2012-03-10 04:57 +0000
Re: SimpleFormatter Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-10 09:26 -0400
Re: SimpleFormatter Question Novice <novice@example..com> - 2012-03-10 17:55 +0000
Re: SimpleFormatter Question Lew <noone@lewscanon.com> - 2012-03-10 10:27 -0800
Re: SimpleFormatter Question Novice <novice@example..com> - 2012-03-10 20:47 +0000
Re: SimpleFormatter Question Arne Vajhøj <arne@vajhoej.dk> - 2012-03-10 12:08 -0500
csiph-web