I have done something very similar to this, only 10 times more complex
as this, using a perl script (which, btw I wrote using emacs :-). It's
1061 lines of hairy regexs. Here is what it does:
#
# The code currently has calls to the logging methods like the
following:
# Log.Log(CATEGORY_NAME, Log.LEVEL, "message " + a + " continue",
exception);
#
# We want to transform this call into a call that looks like the
following:
# Log.CATEGORY_NAME.level(new Message("message {0}
continue").setArgs(a), exception)
#
# This script will do it in 3 passes. Here is what each of the passes
will do
# Pass 1:
# Will convert Log.Log(CAT_NAME, LEVEL, "msg" + a, ex) ->
Log.CAT_NAME.level("msg" + a, ex);
# Pass 2:
# Log.CAT_NAME.level("msg" + a, ex) -> Log.CAT_NAME.level(new
Message("msg" + a), ex);
# Pass 3:
# new Message("msg" + a) -> new Message("(Number)
msg{0}").setArgs(a)
# This pass also has the side effect of writing the properties file
with the
# appropriate internationalized string key/value pairs. It will
only modify
# the new Message("") calls inside logging methods
#
# Bugs/Enhancements
# -----------------
# 1. use same argument number '{number}' for arguments whose spelling
is the same
#
Email me if you're interested, and I can share it.