Hi there, I totally agree with you! At least would be fine to have public void debug(Object messagePattern, Object arg); extended up to 3 arguments and then (for more than 3 arguments) it should use an Object[]. This is the approach used in Logback [1].
Bye Piero [1]http://logback.qos.ch/shortIntro.html Alle 15:22, lunedì 11 dicembre 2006, Morten Hattesen ha scritto: > Hi, > > The Log4J 1.3 API changes to the org.apache.log4j.Logger API was > changed to allow the use of use message patterns > http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/Logger.html > > This was obviously done do avoid excessive string concatenation by the > compiler when calling a logging method, as well as to make the code > more legible. > > Example (log4j 1.2 api): > > logger.debug("Fetching data for " + user.name + " from database"); > > ... may be expressed like so in log4j 1.3: > > logger.debug("Fetching data for {0} from database", user.name); > > As a side effect it is no longer as essential to wrap calls to logging > methods in a conditional ... > > if (logger.isDebugEnabled) { > logger.debug(...); > } > > ... since the string concatenation overhead is now not incurred unless > the logging actually takes place. > > However, what surprises me, is that the API only supports 1 and 2 > argument messages, and that message pattern is not supported at all > when passing a throwable. > > I can see a point in allowing a single argument convenience method > signature, e.g.: > > public void debug(Object messagePattern, Object arg); > > But to support multiple (2 or more) arguments (using JRE 1.2), an > Object array should be used, e.g: > > public void debug(Object messagePattern, Object[] args); > > In other words, I suggest that all the two-argument methods of > org.apache.log4j.Logger (and its deprecated super classes) should be > removed, e.g: > > public void xxxx(String messagePattern, Object arg1, Object arg2); > > ... and replaced by ... > > public void xxxx(String messagePattern, Object[] args); > > > Also, I feel that in order to keep the 1.3 API "clean" the logging > methods that take a throwable argument should be overloaded with > message pattern arguments, too, e.g. > public void trace(Object messagePattern, Object arg, Throwable t); > public void trace(Object messagePattern, Object[] args, Throwable t); > > > Can I please get some views on this subject from other Log4J users, > before submitting it formally to the developers' list. > > Regards, > > Morten Hattesen > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- Q: How do you catch a unique rabbit? A: Unique up on it! Q: How do you catch a tame rabbit? A: The tame way! --------------------------------------- GPG KeyID: 84AE988E Fingerprint: F0A0 CA2A 8D8F CC12 3F5E C04C D8D5 9DC3 84AE 988E gpg --keyserver x-hkp://search.keyserver.net:11371 --recv-key 84AE988E
pgpqEUGP7YWfX.pgp
Description: PGP signature
