- the import of java.util.logging.Logger with org.slf4j.*
- the line constructing the Logger instance to use the slf4j LoggerFactory instead
- .fine, .finer and .finest with .debug (for some reason .debug is the finest level in the slf4j API)
- .warning with .warn
- .severe with .error
#/bin/ksh
for file in `find . -name '*.java'`
do
cleartool co -c "Changing log framework thingie." $file
sed -e 's/java.util.logging.Logger/org.slf4j.*/' \
-e 's/= Logger.getLogger/= LoggerFactory.getLogger/' \
-e 's/.fine(/.debug(/' \
-e 's/.finer(/.debug(/' \
-e 's/.warning(/.warn(/' \
-e 's/.severe(/.error(/' \
$file > $file.tmp
mv $file.tmp $file
done
As you can see I also added a line to check out the file from Clearcase. If you are using CVS, subversion or even git (as any developer would given a free choice....) there is no need.
A couple of files failed to compile after the migration. Curly braces disappeared at the end of some classes and in one case the logger was instantiated on 2 lines instead of one but overall it worked nicely.
This way of working comes rather natural to me but I gather that not all developers think of the command line as a helpful tool and thus this blog post.
4 comments:
Sweet :) What would life be without sed, awk, find and grep. Any developer should have these tools in his toolbox.
Have you looked at the SLF4J migrator? It accomplishes what you describe, except for the fine/finer/finest to debug mapping.
Seems like my 10 line script was a bit better than the migrator then! Sometimes a few lines of unix scripting is all you need. But it is of course good that there are tools since many developers don't have a clue about unix.
Post a Comment