user2250246 user2250246 - 9 months ago 41
Java Question

How to create a non-data gc.log file?

I see that my gc.log files are data files while other log files are ASCII text.

Due to that I cannot grep through the non-gc.log files.

$ pwd

$ du -hsmc *log* | sort -n

50 access_log2016-11-21.log
74 access_log2016-11-25.log
79 access_log2016-11-24.log
300 gc.log-20161118
418 gc.log-20161119
542 gc.log-20161120

$ file access_log2016-11-24.log gc.log-20161118
access_log2016-11-24.log: ASCII text
gc.log-20161118: data

$ time grep a access_log2016-11-24.log | wc -l

real 0m0.888s
user 0m0.740s
sys 0m0.150s

$ time grep a gc.log-20161118
Binary file gc.log-20161118 matches

real 0m9.574s
user 0m9.278s
sys 0m0.274s

You can see that it is taking much longer to grep in the gc.log file and it does not return a useful result.

Argument to print GC into gc.log file is

How do I ensure that the gc.log file is created as an ASCII text file rather than a data file?

Answer Source

Your problem here is that grep is interpreting the GC log as a binary data file, where it is actually text. If you use the -a or --text parameter on grep it will treat it as text.

grep -a a gc.log-20161118