Java Logging - where is my log file?
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"));
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.
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
The .log
file is in your \workspace\.metadata
folder. I'm using Eclipse 4.2.