0
try {
    // Create an appending file handler
    boolean append = true;
    FileHandler handler = new FileHandler("my.log", append);

    // Add to the desired logger
    Logger logger = Logger.getLogger("com.mycompany");
    logger.log(Level.INFO, "This is info message");
    logger.addHandler(handler);
} catch (IOException e) {
}

My problem is when i open my.log file i don't see the text "This is info message" but just

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>

Can anyone point me out where is problem???

3 Answers 3

2

I think you should add handler before you log something.

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

1 Comment

Thank you! You are right i tried adding handler before logging and it worked.
1

You should set the appender before logging anything is logged

try {
    // Create an appending file handler
    boolean append = true;
    FileHandler handler = new FileHandler("my.log", append);

    // Add to the desired logger
    Logger logger = Logger.getLogger("com.mycompany");
    logger.addHandler(handler);

    logger.log(Level.INFO, "This is info message");
    } catch (IOException e) {
}

Comments

0

Quoting from the docs:

Each Logger has a "Level" associated with it.

Maybe the level configured for this logger is too high for INFO level messages to show up.

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.