Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java log in plain text

I redirected Java Logger to log in file using following code:

Handler handler = new FileHandler("test.log", LOG_SIZE, LOG_ROTATION_COUNT);
Logger.getLogger("").addHandler(handler);

but it logs in XML format. I want to be exactly like output (i.e. plain text). How can I do that?

like image 788
MBZ Avatar asked May 06 '12 08:05

MBZ


People also ask

What is FileHandler in Java?

The FileHandler can either write to a specified file, or it can write to a rotating set of files. For a rotating set of files, as each file reaches a given size limit, it is closed, rotated out, and a new file opened. Successively older files are named by adding "0", "1", "2", etc. into the base filename.

How do I enable Java logging?

From the open Java Control Panel, Go to the "Advanced" tab. Open the Debugging section. Select "Enable tracing" and 'Enable logging"


1 Answers

You need to set a Formatter on your Handler. Either create your own or use the SimpleFormatter

like image 130
Guillaume Polet Avatar answered Sep 30 '22 20:09

Guillaume Polet