-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
5.0, 6
-
Cause Known
-
generic, x86
-
generic, linux, windows_xp
Name: rmT116609 Date: 02/24/2004
A DESCRIPTION OF THE REQUEST :
The "convenience" methods of java.util.logging.logger (finest, finer, fine, config, info, warning, and severe) would be more useful if they were extended to use varags. The new signatures would be:
void finest(String, Object...);
void finer(String, Object...);
void fine(String, Object...);
void config(String, Object...);
void info(String, Object...);
void warning(String, Object...);
void servere(String, Object...);
JUSTIFICATION :
This change would enhance the value of the convenience methods by making it possible to use them with arguments. Currently logging a message with arguments requires using the "log" method, which more-or-less requires importing "java.util.logging.Level" and converting the logging call to use a much more clumsy syntax, making it very tempting just to use string concatenation instead of passing arguments.
(Incident Review ID: 240173)
======================================================================
Name: rmT116609 Date: 08/25/2004
A DESCRIPTION OF THE REQUEST :
The Logger methods that take multiple parameters for log messages should
use the variable-arguments facility instead of requiring the caller to create an
Object array and put all the parameters in that array.
JUSTIFICATION :
A. Ease of coding:
logger.info( "xxx x = {0}, y= {1}", a, b )
vs.
logger.info( "xxx x = {0}, y = {1}}", new Object[] {a, b} )
(Review ID: 300577)
======================================================================
I would even suggest adding static overloads to Logger with a Class parameter:
public static void info(Class clazz, String format, Object... args);
// ...
so that you could write even more easily e.g.:
public class Frobnitz {
public static void range(int lo, int hi) {
if (lo > hi) {
Logger.warning(Frobnitz.class, "Invalid range: {0} > {1}", lo, hi);
}
}
}
where the call would be equivalent to
Logger.getLogger(Frobnitz.class.getName()).log(Level.WARNING, "Invalid range: {0} > {1}", new Object[] {lo, hi});
This would make it particular convenient and pleasant to send log messages labelled with the originating class (so that you can easily turn on and off logging at the package or class level). Otherwise you need to use the clumsy and verbose getLogger syntax. (Using a static field for a per-class Logger is reasonable if you are using it a lot, but annoying for just one or two uses.)
- duplicates
-
JDK-6406791 vararg-ify log(Level level, String msg, Object params[])
-
- Closed
-
-
JDK-5047084 Request for variable parameter version of Logger.log(Level, String, Object[])
-
- Closed
-
-
JDK-6263336 java.util.logging.Logger should be retrofitted to take advantage of varargs
-
- Closed
-
-
JDK-6365542 Logging methods should use varargs for format params
-
- Closed
-
-
JDK-6540440 Logger.log(Level,String,Object[]) should be Logger.log(Level,String,Object...)
-
- Closed
-
- relates to
-
JDK-8039952 Simple enhancements to java.util.Logger for code readability
-
- Open
-
(1 relates to)