Question

We use obfuscation jar in our build and we use Log4j2 for logging purpose. However, the informative logs which we are logging as a string are being logged correctly. But, the logs in case of exception, i.e. the trace of exception or exceprion.getmessage() doesnot print the details. That too comes in obfuscated form, i.e. its not readable.

Any suggestions to overcome this problem?

Was it helpful?

Solution

That sounds like expected behaviour... At runtime, class names and package names are scrambled, so stack traces may not look pretty.

Does your obfuscator not have a de-obfuscate function? I imagine it would generate a file with meta-data (mapping between cleartext names and scrambled names) when it does the scrambling.

If your users then have an issue they need support for, they send you their (scrambled) stack trace. You can unscramble that stack trace and make it readable again by using that meta-data file. (You should keep one for every version of your library that you publish.) That's how you would deal with support issues.

OTHER TIPS

You are probably initializing your loggers like this:

Logger logger = LogManager.getLogger(MyClass.class.getName());

This way is useful during development when you rename / refactor your code a lot. But once you are satisfied with your code you should replace that line with a constant name like this:

Logger logger = LogManager.getLogger("my.package.MyClass");

This way the class name - i.e. logger name - wouldn't be obfuscated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top