3

I'm trying to configure Logger to write to a file in the application configuration folder, but I'm not able to figure how to do so, here is the function I use to configure the logging output at program startup:

private void ConfigureLogger(){
    Logger logger = Logger.getLogger(FormLogin.class.getName());

    try{
        FileHandler handler = new FileHandler(getConfigurationFolder()+"\\application.log", 10, 1, true);

        logger.addHandler(handler);
    }
    catch(IOException e){

    }
    logger.log(Level.SEVERE, "test message");
}

The application.log file is created, but the test log is not written in it but in the console application.

5
  • 1
    getting rid of catch(IOException e){ } might help Commented Dec 14, 2012 at 11:09
  • can't do that, Unreported Exception error Commented Dec 14, 2012 at 11:13
  • so you have to fix that Exception first Commented Dec 14, 2012 at 11:17
  • @Joel replace {} with { throw new RuntimeException(e); } Commented Dec 14, 2012 at 11:17
  • I tried that, but doesn't seem to change anything. Commented Dec 14, 2012 at 11:19

1 Answer 1

5

Could you try:

FileHandler handler = new FileHandler("D:/temp/application.log", 8096, 1, true);

Parameters:

  • pattern - the pattern for naming the output file
  • limit - the maximum number of bytes to write to any one file
  • count - the number of files to use
  • append - specifies append mode
Sign up to request clarification or add additional context in comments.

2 Comments

That works, but why can't I write to a file in the configuration folder (C:\Users\Joel\.application)? I already have a function that writes a configuration file in there and it works right.
Can you post your exact code on this? (or atleast the relevant part?)

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.