1

I have the following code;

_fileHandler = new FileHandler(_logFileNameAndpath, true);
_logger = Logger.getLogger("MyLogger");
_logger.addHandler(_fileHandler);
SimpleFormatter formatter = new SimpleFormatter();
_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?

3
  • Why aren't you log4j.properties or log4j.xml? Commented Nov 18, 2010 at 4:23
  • @CoolBeans - This is java.util.logging, not log4j. Commented Nov 18, 2010 at 14:41
  • Aahh, I have not used that in forever. So absolutely forgot about it. Thanks Andy! Commented Nov 18, 2010 at 15:07

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I suggest you to put everything in a StringBuffer and then finally log it at each class or package.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.