Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does java.util.logging.Logger store their log

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.info("Removed order " + id + "."); 

Where do I see the log? Also this quote from java.util.logging.Logger library:

On each logging call the Logger initially performs a cheap check of the request level (e.g. SEVERE or FINE) against the effective log level of the logger. If the request level is lower than the log level, the logging call returns immediately.
After passing this initial (cheap) test, the Logger will allocate a LogRecord to describe the logging message. It will then call a Filter (if present) to do a more detailed check on whether the record should be published. If that passes it will then publish the LogRecord to its output Handlers.`

Does this mean that if I have 3 request level log:

logger.log(Level.FINE, "Something"); logger.log(Level.WARNING, "Something"); logger.log(Level.SEVERE, "Something"); 

And my log level is SEVERE, I can see all three logs, and if my log level is WARNING, then I can't see SEVERE log, is that correct? And how do I set the log level?

like image 269
Thang Pham Avatar asked Jun 11 '10 19:06

Thang Pham


People also ask

Where are the Java logs stored?

On Linux and UNIX computers, the logs are located in the . java/deployment/log directory of the home directory of the user ID under which the Java™ JRE was installed. Java Web Start will create a uniquely named trace file for every independent launch of the application. The files are named javaws.

Where does logger write to in Java?

There are the five logging handlers in Java: StreamHandler: It writes the formatted log message to an OutputStream. ConsoleHandler: It writes all the formatted log messages to the console. FileHandler: It writes the log message either to a single file or a group of rotating log files in the XML format.

Where does logger write to?

Description. The logger command provides an interface to the syslog subroutine, which writes entries to the system log. A Message variable can be specified on the command line, which is logged immediately, or a File variable is read and each line of the File variable is logged.


2 Answers

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.

like image 81
Péter Török Avatar answered Sep 21 '22 04:09

Péter Török


The Java TM Logging Overview is quite interesting to answer all your questions on the Java Logger:

logging overview

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 from FINEST (the lowest priority, with the lowest value) to SEVERE (the highest priority, with the highest value).

like image 33
VonC Avatar answered Sep 23 '22 04:09

VonC