• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

java.util.logging FileHandler filePattern

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.logging always seems to add both a generation number, and a unique number to the logging file I specify. For example, I specify:

logging.filePattern=c:/logs/myApp.log

, but Java creates:

logging.filePattern=c:/database/logs/myApp.log.0.1

How can I prevent java.util.logging from adding the .0.1?
 
author & internet detective
Posts: 41083
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robert,
You want it to add nothing and just log in one file no matter how large it grows? I've always seen rotating log files. Not two numbers, but the ".1" at the end.
 
Jeanne Boyarsky
author & internet detective
Posts: 41083
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as the generation number, if you don't put %g in your pattern, you wouldn't get that number. Try starting with the example in the JavaDoc and then changing one thing at a time:

Thus for example a pattern of "%t/java%g.log" with a count of 2 would typically cause log files to be written on Solaris to /var/tmp/java0.log and /var/tmp/java1.log whereas on Windows 95 they would be typically written to to C:\TEMP\java0.log and C:\TEMP\java1.log

 
Robert Emmons
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:As far as the generation number, if you don't put %g in your pattern, you wouldn't get that number. Try starting with the example in the JavaDoc and then changing one thing at a time:



Thanks for the suggestion, but it does not work for me. Just as I have shown above, I have no %g or %u in my filePattern. Still, both numbers are generated in the filename as I have shown. I can affect the location of the numbers by putting in the %g, and/or %u, but leaving them out does not cause them to be omitted.

In fact, I have reviewed the documentation further, and it says:

java.util.logging.FileHandler docs wrote:If no "%g" field has been specified and the file count is greater than one, then the generation number will be added to the end of the generated filename, after a dot.



I do not see the equivalent statement for %u.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't this be :

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The funny thing is that the pattern should default to %h/java%u.log, so that doesn't explain why you have myApp.log.0.1.

Check you don't have java.util.logging.FileHandler.pattern set somewhere. Make sure java.util.logging.FileHandler.limit is not set either, which would explain why a file number is appended to the name.
 
Robert Emmons
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:Shouldn't this be :



Yes. That would be th proper entry in the logging.properties file.
 
Robert Emmons
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:The funny thing is that the pattern should default to %h/java%u.log, so that doesn't explain why you have myApp.log.0.1.

Check you don't have java.util.logging.FileHandler.pattern set somewhere. Make sure java.util.logging.FileHandler.limit is not set either, which would explain why a file number is appended to the name.



You are right about the FileHandler.limit. When I changed it to 1, the %g number stopped appearing in the file name.

I have found that the %u was appearing in the file name because I was defining 2 FileHandlers with the same FileHandler.pattern. If I only define one, the %u does not appear in the file name. However, if I define 2 with the same pattern, and do not include %u in the pattern, the %u appears at the end of the file name, after the log. Apparently, it defaults to java.log.%u, not java%u.log, which I would prefer.

So, I think my problems are basically solved. As long as I only define one FileHandler with the same patter, the %u term does not appear in the file name. If I set FileHandler.limit=1, the %g term disappears.
 
Marshal
Posts: 75664
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult a question for beginning Java. Moving.
 
Did you miss me? Did you miss this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic