Skip to content
Advertisement

Subclassing java.util.logging.Formatter doesn’t work

I am using java.util.logging for logging (I don’t want to use log4j or anything else).

This is my complete private logging.properties:

JavaScript

This is the code in my program:

JavaScript

Since this gives each log message on 2 lines, I tried this

How do I get java logging output to appear on a single line?

Copied the LogFormatter class in the first reply exactly.

Changed one line in my logging.properties

JavaScript

Now my log has started appearing in XML. I have a strong feeling that the FileHandler doesn’t like my com.mycomp.myproj.LogFormatter and hence defaulting to the default XMLFormatter. How do I figure out why FileHandler isn’t using my LogFormatter class?

Advertisement

Answer

You can set the formatter in the code itself on the FileHandler instance.

JavaScript

The CustomFormatter class is defined as follows.

JavaScript

You can code in CustomFormatter to output the messages in any format you want. Hope this helps.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement