This might be a stupid question but I am a bit lost with java Logger
private static Logger logger = Logger.getLogger(\"order.web.OrderManager\");
logger.inf
Where it goes is dependent on your configuration. There are details about this in the API docs. The log level is the exact reverse of what you said. If you have a configuration of FINE
, everything that is FINE, WARNING, SEVERE
will show up, but if you have it set to SEVERE
then only those will come up.
In general you should use FINE
while debugging and switch to SEVERE
when it is in a production environment.
Where do I see the log?
In a log file or standard output, depending on your actual log handler configuration. This can be set via a property file or directly via the logging API.
Does this mean that if I have 3 request level log...
SEVERE
is the most important (highest priority) and FINE
is the least important message type of the 3 shown in your example. So if your log level is SEVERE
, only the SEVERE
messages get logged. If level is FINE
, all 3 messages get logged.
This is very useful when in real production environment, you may want to log only the errors and possibly warnings (which are - hopefully - fairly rare, but you want to know about them), so you can set log level to WARNING
. However, in your development environment, when e.g. debugging a problem, you want to see all information in the logs, even though it creates a large amount of log data and slows down the application. So you set log level to FINE
or FINEST
.
Here is a good introduction to Java Logging.
Update: a simple example from the above page to configure the logger to log to a file at level FINEST
:
Handler fh = new FileHandler("%t/wombat.log");
Logger.getLogger("").addHandler(fh);
Logger.getLogger("com.wombat").setLevel(Level.FINEST);
To log to the console, replace the FileHandler
above with a ConsoleHandler
:
Handler ch = new ConsoleHandler();
Logger.getLogger("").addHandler(ch);
This is just an example though - in a real app, it is preferable to configure the logging via a config property file.
The Java TM Logging Overview is quite interesting to answer all your questions on the Java Logger
:
You will see your log where the Handler
(s) associated with your Logger
will generate said Log (in a Console
, or in a Stream
...).
The default configuration establishes a single handler on the root logger for sending output to the console.
Log Level:
Each log message has an associated log Level. The Level gives a rough guide to the importance and urgency of a log message. Log level objects encapsulate an integer value, with higher values indicating higher priorities.
The
Level
class defines seven standard log levels, ranging fromFINEST
(the lowest priority, with the lowest value) toSEVERE
(the highest priority, with the highest value).