Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

-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?

like image 330
Ram Avatar asked Dec 18 '14 18:12

Ram


People also ask

How do I enable GC logs in spring boot?

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.

What is PrintGCDateStamps?

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.


1 Answers

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

like image 197
Arkantos Avatar answered Oct 13 '22 00:10

Arkantos