At the moment a default entry looks something like this:
Oct 12, 2008 9:45:18 AM myClassInfoHere
INFO: MyLogMessageHere
How do I get it to do this?
Oct 12, 2008 9:45:18 AM myClassInfoHere - INFO: MyLogMessageHere
Clarification I'm using java.util.logging
As of Java 7, java.util.logging.SimpleFormatter supports getting its format from a system property, so adding something like this to the JVM command line will cause it to print on one line:
Alternatively, you can also add this to your
logger.properties
:I've figured out a way that works. You can subclass SimpleFormatter and override the format method
A bit surprised at this API I would have thought that more functionality/flexibility would have been provided out of the box
Like Obediah Stane said, it's necessary to create your own
format
method. But I would change a few things:Create a subclass directly derived from
Formatter
, not fromSimpleFormatter
. TheSimpleFormatter
has nothing to add anymore.Be careful with creating a new
Date
object! You should make sure to represent the date of theLogRecord
. When creating a newDate
with the default constructor, it will represent the date and time theFormatter
processes theLogRecord
, not the date that theLogRecord
was created.The following class can be used as formatter in a
Handler
, which in turn can be added to theLogger
. Note that it ignores all class and method information available in theLogRecord
.This logging is specific to your application and not a general Java feature. What application(s) are you running?
It might be that this is coming from a specific logging library that you are using within your own code. If so, please post the details of which one you are using.
If you log in a web application using tomcat add:
On VM arguments
This is what I'm using.
You'll get something like...