in my last post to the list I've discussed that unguarded use of logger
method leads to quite some waste of resources. While this may not be a
problem for big desktops/laptop computer this may be an issue for smaller
I attach two per scripts that help to fix this issue. The checkLogger.pl
script locates all java files in a directory and checks for unguarded
and guarded logger calls. Th script looks for the following patterns:
Found as unguarded logger call (.info, .trace):
Found as guarded logger call:
Sometimes the code contains a pattern like this:
This is counted a unguarded (the script checks only one previous line).
The script shows the results:
WhiteboardSessionPacketExtension.java: info: 0/0, debug: 4/0, trace: 0/0
Global: info: 0/0, debug: 32/0, trace: 0/0
checkLogger found unprotected logger calls
A per-file summary, a global summary and an additional info line.
- in the java file the script found 4 unguarded logger.debug calls,
0 guarded logger.debug call.
- All java file in the directory contained 32 unguarded logger.debug calls
and 0 guarded logger.debug call.
The logger.pl script works the same way and fixed unguarded calls.
Caveat: because of the limited parsing feature the construct
This does not do any harm. Most often the compiler eliminates (optimizes)
the second if. To find these constructs you may use the following command:
grep -B 3 'logger\.[dit][enr]' *.java
which displays the logger calls plus 3 lines before the matching line.
However, these constructs are not very often according to my experiences
I'm using these two scripts already to fix the java files in the
impl/protocol and its sub-directories (step by step of course ).
checkLogger.pl (1.67 KB)
logger.pl (2 KB)