(Note that it's more of a Bash question than a Java question, see note below)
When configuring log4j in each class, we do the following:
public class Example {
private static final Logger log = Logger.getLogger( Example.class );
The problem is that we now have a medium-sized codebase (200K LOC) containing a lot of Java classes and... Quite some misconfigured log4j loggers.
It's because people (including me, I admit), did silly cut'n'paste resulting sometimes in this:
public class Another {
private static final Logger log = Logger.getLogger( Example.class );
And boom, instead of having Another.class, it's the old Example.class that is left and hence wrongly appearing in the logs (hence causing quite a few headaches).
I find it kind of weird that such kind of misconfiguration can happen but it can and our main issue now is not that it can happen but that we have to fix the misconfured loggers.
How can we go about automatically detecting these? (the fix can be manual but I'd like a way to find all the classes where log4j is misconfigured).
A Bash shell script, for example, would be very welcome.
- for every .java file
- find every "class XXX"
- parse the next 'x' lines (say 20)
- is there a Logger.getLogger(...) line?
- if yes, does it match the "class XXX"?
- if no report
False positive ain't an issue so it's not a problem if a few bogus "class XXX" are parsed etc.
NOTE: the problem is really that we now have 200 000 lines of code and we'd like to detect the violation automatically (the fix can be manual) so the question is not similar to:
[Is there a better way to get the current class variable in java?1
Actually it's probably more of a Bash question than a Java question :)
Any help on this most welcome.