Java Logging - where is my log file?
Asked Answered
F

7

37

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.

Friary answered 26/2, 2012 at 22:42 Comment(1)
If you'd like more control over your logs, may I suggest pulling in another library called Logback? Or you could check out log4j.Stound
R
20

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"));
Raybourne answered 27/2, 2012 at 3:30 Comment(7)
I'm using Eclipse 3.7.1 and have a few different JREs installed but the one I'm using in this sandbox project is a 1.6.0_18 JDK. The logging.properties file is in C:\Program Files\Java\jdk1.6.0_18\jre\lib. Sorry, I wanted a line break here but when I press Enter, it closes the window. When I tried the System.out.println() I got a null. Clearly my code isn't seeing the logging.properties file and that's why the log file isn't going where I want it to go. Now I need to figure out why it can't see the logging.properties. Well, I'll start looking and if anyone has suggestions, I'm listening...Friary
I asked how to add the logging.properties file to the classpath in a fresh question and did what I was told. The println() is now giving me the path to the logging,properties file instead of the null. But I'm still not seeing my log file. I've got the same five javaX.log files as before and all of them are unchanged. Any ideas on how to figure this out?Friary
Can someone provide further info? What is the answer to the question of "where is my log file?" What clue does printing out the location of the properties file provide? This is unclear to me.Vegetarian
if it prints null it's probably not finding the one inside your project and using the global one (the one in the JRE or JDK program directory)Yim
@golimar, yes, it prints null and it seems not log file is generated. I download the project from someone and I am new to Java. I do not understand why private static final Logger LOGGER = LogManager.getLogger(ClassName..class.getName()) is used for. And if log history is generated, where is the log file stored?Concertmaster
@YuXiang If you have the filename in your log file you can search for it on the filesystem by name and date, or even with Process Monitor you can see any file that the java.exe process is reading or writingYim
@golimar, thank you for the advice. It seems that in my case, no log file is created and the log information is printed on the terminal directly.Concertmaster
N
3

The .log file is in your \workspace\.metadata folder. I'm using Eclipse 4.2.

Nonmetallic answered 2/8, 2013 at 2:58 Comment(0)
R
3

The root cause of the problem the questioner is having is that his logging.properties file is not being read.
The file specified in java.util.logging.config.file is not read from the classpath. Instead it is read from the file system relative the current directory.
For example, running the following command java -Djava.util.logging.config.file=smclient-logging.properties SMMain will read the smclient-logging.properties from the current directory. Once the correct java.util.logging.config.file is read, the logs are generated as specified in the file.

Ricks answered 19/7, 2016 at 5:26 Comment(0)
S
3

It seems that the default location has changed. To find your logfile open the Java Console with your application. in there press "s". This prints out the System- and Deployment-Properties where you can find something like:

deployment.user.logdir = C:\Users\username\AppData\LocalLow\Sun\Java\Deployment\log

There you will find your logfiles.

Stelliform answered 3/8, 2016 at 12:25 Comment(0)
A
3

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
Assets answered 31/1, 2017 at 5:30 Comment(2)
-Djava.util.logging.config.file= does not result in log being put in current directory. Do you have more information on the CL approach? Is relative path not allowed?Banderole
What is home directory?Hy
K
0

If its null, then the file path would be your eclipse home directory. Your logging.properties file is not raken by the system, so point the properties file to the complete path as shown below then your log file will be generated in the place of directlyr where yor prefers it. -Djava.util.logging.config.file=D:\keplereclipse\keplerws\NFCInvoicingProject\WebContent\WEB-INF\logging.properties

Katzen answered 29/12, 2013 at 11:17 Comment(0)
M
0
  1. Debug the your variable or logger.getHandlers(): just for the instances of FileHandler, and look for its private field: files
  2. Make sure that your logger level including your log.
  3. Make sure that your handler level including your log.
  4. It will be sent to your home directory. If there's no that directory in your operate system, such as windows 95/98/ME, the file should be saved to the default path like C:\Windows\.
  5. Reflect, the same as tip 1

    Field[] handlerFiles = handler.getClass().getDeclaredFields();
    AccessibleObject.setAccessible(handlerFiles, true);
    
    for (Field field : handlerFiles) {
        if (field.getName().equals("files")) {
            File[] files = (File[]) field.get(handler);
            System.out.println(Arrays.toString(files));
        }
    }
    
  6. The log manager will be initialized during JVM startup and completed before the main method. You can also re-initialize it in main method with System.setProperty("java.util.logging.config.file", file), which will call LogManager.readConfiguration().

Melvinmelvina answered 28/1, 2019 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.