Search in sources :

Example 31 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project ACS by ACS-Community.

the class JDK14LoggerAdapter method debug.

/**
   * Log a message at level FINE according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the FINE level.
   * </p>
   * 
   * @param format
   *          the format string
   * @param argArray
   *          an array of arguments
   */
public void debug(String format, Object... argArray) {
    if (logger.isLoggable(Level.FINE)) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
        log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable());
    }
}
Also used : FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 32 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project ACS by ACS-Community.

the class JDK14LoggerAdapter method trace.

/**
   * Log a message at level FINEST according to the specified format and
   * arguments.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the FINEST level.
   * </p>
   * 
   * @param format
   *          the format string
   * @param argArray
   *          an array of arguments
   */
public void trace(String format, Object... argArray) {
    if (logger.isLoggable(Level.FINEST)) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
        log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable());
    }
}
Also used : FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 33 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project ACS by ACS-Community.

the class JDK14LoggerAdapter method error.

/**
   * Log a message at the SEVERE level according to the specified format and
   * argument.
   * 
   * <p>
   * This form avoids superfluous object creation when the logger is disabled
   * for the SEVERE level.
   * </p>
   * 
   * @param format
   *          the format string
   * @param arg
   *          the argument
   */
public void error(String format, Object arg) {
    if (logger.isLoggable(Level.SEVERE)) {
        FormattingTuple ft = MessageFormatter.format(format, arg);
        log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable());
    }
}
Also used : FormattingTuple(org.slf4j.helpers.FormattingTuple)

Example 34 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project sling by apache.

the class JSONRecordingTest method logs.

@Test
public void logs() throws Exception {
    StringWriter sw = new StringWriter();
    JSONRecording r = new JSONRecording("abc", request, true);
    FormattingTuple tp1 = MessageFormatter.arrayFormat("{} is going", new Object[] { "Jack" });
    r.log(tc, Level.INFO, "foo", tp1);
    r.log(tc, Level.WARN, "foo.bar", MessageFormatter.arrayFormat("Jill is going", null));
    r.log(tc, Level.ERROR, "foo.bar", MessageFormatter.arrayFormat("Jack and {} is going", new Object[] { "Jill", new Exception() }));
    r.done();
    r.render(sw);
    JsonObject json = Json.createReader(new StringReader(sw.toString())).readObject();
    assertEquals(3, json.getJsonArray("logs").size());
    JsonObject l1 = json.getJsonArray("logs").getJsonObject(0);
    assertEquals("INFO", l1.getString("level"));
    assertEquals("foo", l1.getString("logger"));
    assertEquals(tp1.getMessage(), l1.getString("message"));
    assertEquals(1, l1.getJsonArray("params").size());
    assertFalse(l1.containsKey("exception"));
    assertFalse(l1.containsKey("caller"));
    assertTrue(l1.containsKey("timestamp"));
    JsonObject l3 = json.getJsonArray("logs").getJsonObject(2);
    assertNotNull(l3.get("exception"));
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) FormattingTuple(org.slf4j.helpers.FormattingTuple) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 35 with FormattingTuple

use of org.slf4j.helpers.FormattingTuple in project sling by apache.

the class DefaultDistributionLog method internalLog.

private void internalLog(LogLevel level, String fmt, Object... objects) {
    try {
        FormattingTuple fmtp = MessageFormatter.arrayFormat(fmt, objects);
        internalLog(level, fmtp.getMessage());
    } catch (Throwable e) {
        logger.error("cannot add entry log", e);
    }
}
Also used : FormattingTuple(org.slf4j.helpers.FormattingTuple)

Aggregations

FormattingTuple (org.slf4j.helpers.FormattingTuple)61 LocationAwareLogger (org.slf4j.spi.LocationAwareLogger)5 LogRecord (java.util.logging.LogRecord)4 LogTask (alien4cloud.topology.task.LogTask)3 LogCapture (org.opendaylight.infrautils.testutils.LogCapture)2 DolphinLoggerBridge (com.canoo.platform.logging.spi.DolphinLoggerBridge)1 LogMessage (com.canoo.platform.logging.spi.LogMessage)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JsonObject (javax.json.JsonObject)1 Test (org.junit.Test)1