Java Logger Object not appending to log file
I have the following code;
_fileHandler = new FileHandler(_logFileNameAndpath, true);
_logger = Logger.getLogger("MyLogger");
_logger.addHandler(_fileHandler);
SimpleFormatter formatter = new SimpleFormatte开发者_StackOverflowr();
_fileHandler.setFormatter(formatter);
_logger.log(Level.INFO, message);
However, the logging, to me at least, looks weird in that it creates something like 100 files all named with a numeric extension such at .75, .76, .77 etc.
Can anyone shed any light as to how to make the logger append to the specified file?
Try this:
_fileHandler = new FileHandler(_logFileNameAndpath, true, 1 );
The last argument is:
count - the number of files to use
Incidentally, you can also configure logging through a file sometimes named ''logging.properties,'' specified through the property java.util.logging.config.file
. You can find a sample logging.properties file, with instructions, in your JRE directory tree.
I suggest you to put everything in a StringBuffer and then finally log it at each class or package.
精彩评论