Xloggc not creating log file if path doesn't exist for the first time

7.5k Views Asked by At
-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?

1

There are 1 best solutions below

0
On BEST ANSWER

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