Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Java) writing events to log text file

I am trying to write the events in a log file but no file is being created. I am getting no error at all. Here is the 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);//Loget Info, Warning dhe Severe do ruhen
    fileTxt = new FileHandler("c:/SimleTaskEvents.txt");
    formatterTxt = new SimpleFormatter();
    fileTxt.setFormatter(formatterTxt);
    logger.addHandler(fileTxt);

}
}
like image 407
Han Avatar asked Dec 20 '12 10:12

Han


2 Answers

You need to write to the log first

logger.info("this is a line of logging");

and maybe check this tutorial

like image 154
emeraldjava Avatar answered Nov 15 '22 01:11

emeraldjava


fileTxt = new FileHandler("c:/SimleTaskEvents.txt");

This line only creates a handler.

It does not create the file. What you need to do is, create the file(SimleTaskEvents.txt) in the directory "C:/". after that when u execute your program, the same program that u have put here, you will see logs being written to it.

like image 33
manick Avatar answered Nov 15 '22 01:11

manick