I'm having trouble finding my log files.
I'm using Java Logging - java.util.logging
- in Eclipse 3.7.1 on Windows XP. The relevant lines of my logging.properties
file are:
handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler .level=INFO java.util.logging.FileHandler.pattern = %h/java%u.log java.util.logging.FileHandler.limit = 50000 java.util.logging.FileHandler.count = 1 java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
As far as I can figure out, after I execute these two lines:
Logger logger = Logger.getLogger("test"); logger.logp(Level.INFO, "myClass", "myMethod", "Alcatraz");
my log file should be in C:\Documents and Settings\[My Windows ID]\javaX.log
where X
is an integer.
I have 5 different java.log
files in that directory, java0.log
through java4.log
, but none of them contain my log record or even a record with today's date on it. I did some googling and found Tracing and Logging which implies that my logs should be at a different location, c:\Documents and Settings\[My Windows ID]\Application Data\Sun\Java\Deployment\log
. There is one file there, named plugin5581819941091650582.log
, but it is essentially empty:
<?xml version="1.0" encoding="windows-1252" standalone="no"?> <!DOCTYPE log SYSTEM "logger.dtd"> <log> </log>
Its creation date is last week. (I'm not sure what process created it; I certainly didn't create it explicitly.)
So where is my log file then? I can't think of anywhere else to look.
Also, does anyone know when changes to logging.properties
take effect? If I changed the log level or the FileHandler.pattern
, what would have to happen before my program saw the changes? Simply saving the changes in logging.properties
is clearly not enough. Will I need to restart Eclipse? Or reboot the computer? Just curious. That's not nearly as big a deal to me as finding out where my log file actually is.
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.
Double-click on the log file and it will likely open in a text program by default, or you can choose the program you'd like to use to open the file by using the right-click and “Open With” option. Another option is to use a web browser and open the server log file in HTML.
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.
slf4j is only an API. You should have a concrete implementation (for example log4j). This concrete implementation has a config file which tells you where to store the logs. When slf4j catches a log messages with a logger, it is given to an appender which decides what to do with the message.
Location of log file can be control through logging.properties file. And it can be passed as JVM parameter ex : java -Djava.util.logging.config.file=/scratch/user/config/logging.properties
Details: https://docs.oracle.com/cd/E23549_01/doc.1111/e14568/handler.htm
Configuring the File handler
To send logs to a file, add FileHandler to the handlers property in the logging.properties file. This will enable file logging globally.
handlers= java.util.logging.FileHandler
Configure the handler by setting the following properties:
java.util.logging.FileHandler.pattern=<home directory>/logs/oaam.log java.util.logging.FileHandler.limit=50000 java.util.logging.FileHandler.count=1 java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern specifies the location and pattern of the output file. The default setting is your home directory.
java.util.logging.FileHandler.limit specifies, in bytes, the maximum amount that the logger writes to any one file.
java.util.logging.FileHandler.count specifies how many output files to cycle through.
java.util.logging.FileHandler.formatter specifies the java.util.logging formatter class that the file handler class uses to format the log messages. SimpleFormatter writes brief "human-readable" summaries of log records.
To instruct java to use this configuration file instead of $JDK_HOME/jre/lib/logging.properties:
java -Djava.util.logging.config.file=/scratch/user/config/logging.properties
Where is your logging.properties
file located? It should be available in the root of the classpath. As a sanity check, what does the following code print?
System.out.println(getClass().getClassLoader().getResource("logging.properties"));
If the code is in a static
context, use
System.out.println(ClassName.class.getClassLoader().getResource("logging.properties"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With