Xloggc does not create a log file if the path does not 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 

Above is the full list of JAVA_OPTS that I pass for my application. The problem is that the gc.log file is not created sometimes if the log directory does not exist by the time the application starts. But gc.log is always created if I am sure that the log directory exists by the time the application starts.

I understand correctly that before my log4j platform creates a log directory, if GC happens, will Xloggc work safely? Is there a different workaround than pre-creating the log directory?

+5
source share
1 answer

Yes, for -Xloggc to create a log file, a directory must always exist. Creating a catalog manually is the easiest task. In most projects, a magazine catalog is always available. But if you need to clear the logs, I suggest deleting all the files in the logs directory, but leaving the directory intact.

You can even write a shell script to create a log directory and then start your server, but you should use this script instead of the standard startup scripts for all server reboots.

+2
source

Source: https://habr.com/ru/post/1209477/


All Articles