-Xss256k
-Djava.net.preferIPv4Stack=true
-Dfile.encoding=UTF-8
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+DisableExplicitGC
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintGCTimeStamps
-XX:+PrintClassHistogram
-XX:+PrintClassHistogramBeforeFullGC
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintPromotionFailure
-XX:PrintFLSStatistics=1
-verbose:gc
-XX:GCLogFileSize=64m
-XX:NumberOfGCLogFiles=2
-XX:+UseGCLogFileRotation
-Xloggc:./logs/gc.log
The above are the complete list of JAVA_OPTS I'm passing for my application. The problem is that gc.log file is not being created sometimes if the logs directory doesn't exist by the time application starts. But gc.log is created always if I make sure that the logs directory exists by the time application starts.
So am I right in assuming that before my log4j framework creates the logs directory if a GC occurs, Xloggc will fail safely? Is there any other workaround other than pre-creating the logs directory manually?
To enable GC logging: Add the following line to the setenv. bat file: set CATALINA_OPTS=-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCCause -Xloggc:[filename]replacing [filename] with the path to the file that you would like to create to store the log file.
First, -XX:+PrintGCDateStamps adds the date and time of the log entry to the beginning of each line. Second, -XX:PrintGCTimeStamps adds a timestamp to every line of the log detailing the time passed (in seconds) since the JVM was started.
Yes for -Xloggc
to create a log file, the directory should always exist.
Creating a directory manually is the easiest thing to do. In most of the projects, logs directory is always available. But if you ever need to clear the logs, I suggest that you delete all the files in logs
directory but leave the directory intact.
You can even write a shell script to create the logs directory and then start your server, but you've to use this script instead of standard startup scripts for all your server restarts
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