开发者

Java Logger Object not appending to log file

开发者 https://www.devze.com 2023-01-25 21:34 出处:网络
I have the following code; _fileHandler = new FileHandler(_logFileNameAndpath, true); _logger = Logger.getLogger(\"MyLogger\");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消