You may think it a stupid question, but surely I found no specification for it.
I have a mini-program that needs to log success and failures upon execution and I need the log to be kept apart from default ones so I can easily read it every time. Originally I put:
Logger.getLogger("Success").addHandler(new FileHandler("var/success.log", true));
My intention was to have a growing log and that every time I executed the program, the log would be growing. When I look at the log, it actually just has a lot of headers, once for each time I executed that line, even if no log was saved. I am pretty sure this isn't how it should work, I don't have 1 unique big log anymore but a lot of them in a single file, and switching to another formatter doesn't feel like a solution at all (i still need XML).
One solution I am currently searching for is to open a fresh file at every execution. The Pattern in the constructor doesn't seem to help with this. %u only test for already open or impossible to write, but with or without append enabled, an existing file won't stop this handler. And for %g, a rotating, it just rotates on size but the same I don't identify the previous log problem still happens.
is there a way to get there by modifying the Logger
, LogManager
, the constructor or the Filehandler
? A my-own and specific solution using Files (or Path or File or whatever) to check for every combination before opening the logger doesn't seem efficient and its something I really don't really want to worry about.
Also, is there a way to get the FileHander
to actually read the file input and CONTINUE with the log where it was left, instead of creating a new one with new headers?
This seconds question, although it fits my needs better, seems harder to get (but what would I know?), so I can work with the first one.
Thanks!