Look in the following code:

**FileHandler txtLog = new FileHandler("log/server-%u%g.log", 0, 1, true);**

 txtLog.setFormatter(new SimpleTextFormatter());
            BasicServerConfig config = qs.getBasicConfig();
            log.fine("Getting the log level.. from server.xml, after loading Quick Server...");
            txtLog.setLevel(Level.parse(config.getConsoleLoggingLevel()));
            log.setLevel(Level.parse(config.getConsoleLoggingLevel()));
            log.addHandler(txtLog);
            qs.setAppLogger(log);

I want that this file should be created with each new date (with out time).

link|improve this question
This should be transfered to stackoverflow.com – Philippe Carriere Dec 3 '09 at 15:58
Don't know if it should or not. As Linux admin, I would much rather the app just behaves like everything most things so it can be used with logrotate. But I don't know Java, so don't know if Java can catch those signals and act like normal programs. – Kyle Brandt Dec 3 '09 at 16:17
As the question is being put, it's a coding question suited for stackoverflow. – MattBianco Mar 31 '11 at 11:02
feedback

1 Answer

From the Linux perspective, the general way would be to use logrotate to rotate the logs. Then have you program handle the HUP signal to reopen the new logs and set up lograte to send that signal to program.

If you want to do this all within Java, then you should go ask on stackoverflow.com .

link|improve this answer
Definitely Stackoverflow... what you want is log4j: logging.apache.org/log4j/1.2/index.html...Log4j is very configurable, and has appenders/plugins for almost everything you might want, including one that can automatically rotate files based on date and size. – mfarver Dec 3 '09 at 14:52
But java is broken, you have no guarantee that flock() type cooperation is going to be honored, since it might not work elsewhere -- Windoze, Mac. Stupid java... (sez the java programmer) – Roboprog Jan 6 '10 at 18:11
P.S. - I don't mean literally broken, just that it disregards current unix conventions for log file handling so as to be annoyingly portable. – Roboprog Jan 6 '10 at 18:12
feedback

Your Answer

 
or
required, but never shown