[Lumberjack-users] parameters are ignored in SimpleFormatter
Status: Beta
Brought to you by:
gilstrap
|
From: Bruno H. <ha...@il...> - 2001-08-17 14:16:57
|
Hello dear javalogging implementors,
Without this fix, an 'info' call with parameters ignores the
parameters, i.e. produces output like this:
Aug 17, 2001 04:00:15 PM ilog.cpl.util.IlpForwardingHandler publish INFO: >> event {0}
But what I need is output like this:
Aug 17, 2001 04:03:32 PM ilog.cpl.util.IlpForwardingHandler publish INFO: >> event ilog.cpl.network.NetworkModelEvent[ROOT_OBJECT_ADDED,model=ilog.cpl.network.IlpDefaultNetworkModel@114f6a,object=ilog.cpl.network.IlpDefaultNetworkNode@71dc3d]
Here is a fix.
diff -c -3 -r1.1.2.1 SimpleFormatter.java
*** SimpleFormatter.java 2001/08/17 13:25:49 1.1.2.1
--- SimpleFormatter.java 2001/08/17 14:07:22
***************
*** 51,57 ****
msg.append( " " );
msg.append( record.getLevel() );
msg.append( ": " );
! msg.append( record.getMessage() );
msg.append( "\n" );
return msg.toString();
}
--- 51,57 ----
msg.append( " " );
msg.append( record.getLevel() );
msg.append( ": " );
! msg.append( formatMessage( record ));
msg.append( "\n" );
return msg.toString();
}
And in order to avoid NullPointerExceptions coming from
Formatter.FormatMessage
Exception in thread "main" java.lang.NullPointerException
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:582)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:546)
at java.util.logging.Formatter.formatMessage(Formatter.java:41)
at java.util.logging.SimpleFormatter.format(SimpleFormatter.java:55)
at java.util.logging.StreamHandler.publish(StreamHandler.java:188)
at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:55)
at java.util.logging.LogManager.publish(LogManager.java:203)
at java.util.logging.Logger.log(Logger.java:298)
I also commented out a piece of code in Formatter.FormatMessage:
diff -c -3 -r1.1.2.1 Formatter.java
*** Formatter.java 2001/08/17 13:25:47 1.1.2.1
--- Formatter.java 2001/08/17 14:07:22
***************
*** 34,39 ****
--- 34,40 ----
* will not be available until JDK 1.4.
*/
public String formatMessage( LogRecord record ) {
+ /*
String key = record.getMessage();
ResourceBundle bundle = record.getResourceBundle();
if ( bundle == null ) {
***************
*** 49,54 ****
--- 50,57 ----
formatString = key;
}
}
+ */
+ String formatString = record.getMessage();
Object[] parameters = record.getParameters();
if ( parameters == null || parameters.length == 0 ) {
return formatString;
All the best,
Bruno
|