WRITING EVENTS TO LOG TEXT FILE USING JAVA

Kate Smith

Total Post:24

Points:168
Posted by  Kate Smith
Java 
 1059  View(s)
Ratings:
Rate this:

The below line of code I am trying to write the events in a log file but no file is being created and I am also not getting any kind of error at all.

My log class:

public class Logs {
static FileHandler fileTxt;
static SimpleFormatter formatterTxt;
static public void logging() throws IOException {
    Logger logger = Logger.getLogger("");
    logger.setLevel(Level.INFO);
    fileTxt = new FileHandler("c:/SimleTaskEvents.txt");
    formatterTxt = new SimpleFormatter();
    fileTxt.setFormatter(formatterTxt);
    logger.addHandler(fileTxt);
}
}
  1. Hank Greenberg

    Post:12

    Points:84
    Re: Writing events to log text file using java

    You should write to the log first logger.info("my logging line");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!