how to append timestamp to file name for java.util.logging.FileHandler.pattern
Asked Answered
E

3

6

Hi I was wondering if anyone knows a way to append a timestamp to the log file name specified through logging.properties java.util.logging.FileHandler.pattern

seems like something pretty straight forward but I cant seem to find a solution to this anywhere.

Thanks

Ethelinda answered 24/3, 2010 at 6:19 Comment(1)
Why don't you use log4j?Honeysweet
S
4

I am afraid that just by configuration you can't set the file name in teh way you want.

Have a look at the code in FileHandler.generate() to convince you.

What you can do is write your own FileHandler that will handle this naming or switch to another log framework.

If you use java.util.logging, I wrote some years ago a Formatter & a Handler that can still be usefull, feel free to use.

Sciatica answered 20/5, 2010 at 12:19 Comment(0)
M
1

You could instantiate the FileHandler in code with pattern, limit, count etc parameters. So, the pattern string can be formed consisting of date and time.

Example Code:

String timeStamp = new SimpleDateFormat().format( new Date() );
FileHandler fh = new FileHandler( "./jay_log_%u.%g_" + timeStamp + ".log", 30000, 4);
logger.addHandler(fh);
Mantra answered 24/9, 2010 at 13:0 Comment(0)
S
0

You could use SLF4J which points again back to java.util.logging packages which seems to have this feature http://javablog.co.uk/2008/07/12/logging-with-javautillogging/

alternatively for a no-third-party-frameworks approach you can use a CustomFormatter a sample of which is already available here, http://www.kodejava.org/examples/458.html

Spectrograph answered 24/3, 2010 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.