/** * Pushes new diagnostic context information for the current thread. * * <p> * The contents of the <code>message</code> and args parameters are determined solely by the client. The message * will be treated as a format String and tokens will be replaced with the String value of the arguments in * accordance with ParameterizedMessage. * </p> * * @param message The new diagnostic context information. * @param args Parameters for the message. */ public static void push(final String message, final Object... args) { contextStack.push(ParameterizedMessage.format(message, args)); }
@Test public void testFormatStringArgsWithEscape() { final String testMsg = "Test message \\{}{} {}"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message {}a b", result); }
@Test public void testFormatStringArgsWithEscapedEscape() { final String testMsg = "Test message \\\\{}{} {}"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message \\ab c", result); }
@Test public void testFormatNullArgs() { final String testMsg = "Test message {} {} {} {} {} {}"; final String[] args = { "a", null, "c", null, null, null }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message a null c null null null", result); }
@Test public void testFormatStringArgsIgnoresSuperfluousArgs() { final String testMsg = "Test message {}{} {}"; final String[] args = { "a", "b", "c", "unnecessary", "superfluous" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message ab c", result); }
@Test public void testFormat3StringArgs() { final String testMsg = "Test message {}{} {}"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message ab c", result); }
@Test public void testFormatStringArgsWithTrailingEscape() { final String testMsg = "Test message {}{} {}\\"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message ab c\\", result); }
@Test public void testFormatStringArgsWithTrailingText() { final String testMsg = "Test message {}{} {}Text"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message ab cText", result); }
@Test public void testFormatStringArgsWithTrailingEscapedEscape() { final String testMsg = "Test message {}{} {}\\\\"; final String[] args = { "a", "b", "c" }; final String result = ParameterizedMessage.format(testMsg, args); assertEquals("Test message ab c\\\\", result); }
@Override public void error(Throwable error, String message, Object... args) { if (logger.isErrorEnabled()) { String formatted = ParameterizedMessage.format(message, args); logger.error(formatted, error); } } }
@Override public void error(Throwable error, String message, Object... args) { if (logger.isErrorEnabled()) { String formatted = ParameterizedMessage.format(message, args); logger.error(formatted, error); } } }
/** * Pushes new diagnostic context information for the current thread. * * <p> * The contents of the <code>message</code> and args parameters are determined solely by the client. The message * will be treated as a format String and tokens will be replaced with the String value of the arguments in * accordance with ParameterizedMessage. * </p> * * @param message The new diagnostic context information. * @param args Parameters for the message. */ public static void push(final String message, final Object... args) { contextStack.push(ParameterizedMessage.format(message, args)); }