2

There is an issue we are facing in production environment. The File generated using log4j is getting appended with some special characters at the start of file, before starting to log. This is resulting in a binary file which is making tools like Splunk not able to access these files as it is expecting text files.

Please help me what could be the issue here.

  • 1
    what characters are being put there? is it a Byte Order Marker (BOM)? – Paul Ostrowski Aug 01 '16 at 23:47
  • The characters are "^@^@^@^@" – Jayesh K Wadikar Aug 02 '16 at 04:01
  • Which log4j version are you using? Can you post here your log4j configuration file and/or the Pattern you use? – xav Aug 02 '16 at 21:42
  • I am using the log4j version 1.2.13 and also one more thing the characters are appearing on the rotation of the logs. I am using Rolling File Appender. I also tried using Append as both true and false and set the encoding as UTF-8. This is not fixing the issue. – Jayesh K Wadikar Aug 02 '16 at 23:32
  • 1
    @JayeshKWadikar If you think the answer below helped you, please upvote/mark it as "accepted" (stackoverflow.com/help/someone-answers) so that other people know it worked for you :) (else, feel free to comment) – xav Aug 08 '16 at 19:55

1 Answers1

0

According to Google, my best guess is that you are using GC logs (JVM Garbage Collector logs) from what I read here: https://developer.jboss.org/message/529671#529671 and here: https://developer.jboss.org/thread/148848?tstart=0&_sscc=t.

It seems that there is no real solution, except maybe using the right combination of ASCII encoding + right locale, according to the pages previously linked.

Since you said, in your question, that you have this problem on production environment, I may suggest you to simply disable GC logs in production, because you should not do this in production (enabling GC logs have a performance/storage impact). In your JVM start options, look for something like -XX:+PrintGC or -verbose:gc.

xav
  • 5,452
  • 7
  • 48
  • 57