Search in sources :

Example 31 with Logger

use of java.lang.System.Logger in project logging-log4j2 by pwntester.

the class Log4jSystemLoggerTest method testLogWithCallingClass.

@Test
public void testLogWithCallingClass() throws Exception {
    final Logger log = System.getLogger("Test.CallerClass");
    log.log(Logger.Level.INFO, "Calling from LoggerTest");
    final List<String> messages = stringAppender.getMessages();
    assertThat(messages, hasSize(1));
    final String message = messages.get(0);
    assertEquals(Log4jSystemLoggerTest.class.getName(), message);
}
Also used : Logger(java.lang.System.Logger) Test(org.junit.Test)

Example 32 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class AbstractLoggerWrapper method logp.

@Override
public void logp(PlatformLogger.Level level, String sourceClass, String sourceMethod, Supplier<String> msgSupplier) {
    final PlatformLogger.Bridge platformProxy = platformProxy();
    if (platformProxy == null) {
        // best effort
        if (sourceClass == null && sourceMethod == null) {
            wrapped().log(level.systemLevel(), msgSupplier);
        } else {
            Level systemLevel = level.systemLevel();
            Logger wrapped = wrapped();
            if (wrapped.isLoggable(systemLevel)) {
                final String sClass = sourceClass == null ? "" : sourceClass;
                final String sMethod = sourceMethod == null ? "" : sourceMethod;
                wrapped.log(systemLevel, () -> String.format("[%s %s] %s", sClass, sMethod, msgSupplier.get()));
            }
        }
    } else {
        platformProxy.logp(level, sourceClass, sourceMethod, msgSupplier);
    }
}
Also used : Level(java.lang.System.Logger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 33 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class AbstractLoggerWrapper method logp.

@Override
public void logp(PlatformLogger.Level level, String sourceClass, String sourceMethod, String msg, Throwable thrown) {
    final PlatformLogger.Bridge platformProxy = platformProxy();
    if (platformProxy == null) {
        // best effort
        if (sourceClass == null && sourceMethod == null) {
            wrapped().log(level.systemLevel(), msg, thrown);
        } else {
            Level systemLevel = level.systemLevel();
            Logger wrapped = wrapped();
            if (wrapped.isLoggable(systemLevel)) {
                sourceClass = sourceClass == null ? "" : sourceClass;
                sourceMethod = sourceMethod == null ? "" : sourceMethod;
                msg = msg == null ? "" : msg;
                wrapped.log(systemLevel, String.format("[%s %s] %s", sourceClass, sourceMethod, msg), thrown);
            }
        }
    } else {
        platformProxy.logp(level, sourceClass, sourceMethod, msg, thrown);
    }
}
Also used : Level(java.lang.System.Logger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 34 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class AbstractLoggerWrapper method logp.

@Override
public void logp(PlatformLogger.Level level, String sourceClass, String sourceMethod, String msg, Object... params) {
    final PlatformLogger.Bridge platformProxy = platformProxy();
    if (platformProxy == null) {
        // best effort
        if (sourceClass == null && sourceMethod == null) {
            wrapped().log(level.systemLevel(), msg, params);
        } else {
            Level systemLevel = level.systemLevel();
            Logger wrapped = wrapped();
            if (wrapped.isLoggable(systemLevel)) {
                sourceClass = sourceClass == null ? "" : sourceClass;
                sourceMethod = sourceMethod == null ? "" : sourceMethod;
                msg = msg == null ? "" : msg;
                wrapped.log(systemLevel, String.format("[%s %s] %s", sourceClass, sourceMethod, msg), params);
            }
        }
    } else {
        platformProxy.logp(level, sourceClass, sourceMethod, msg, params);
    }
}
Also used : Level(java.lang.System.Logger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Example 35 with Logger

use of java.lang.System.Logger in project Bytecoder by mirkosertic.

the class AbstractLoggerWrapper method logrb.

@Override
public void logrb(PlatformLogger.Level level, String sourceClass, String sourceMethod, ResourceBundle bundle, String msg, Throwable thrown) {
    final PlatformLogger.Bridge platformProxy = platformProxy();
    if (platformProxy == null) {
        // best effort
        if (bundle != null || sourceClass == null && sourceMethod == null) {
            wrapped().log(level.systemLevel(), bundle, msg, thrown);
        } else {
            Level systemLevel = level.systemLevel();
            Logger wrapped = wrapped();
            if (wrapped.isLoggable(systemLevel)) {
                sourceClass = sourceClass == null ? "" : sourceClass;
                sourceMethod = sourceMethod == null ? "" : sourceMethod;
                msg = msg == null ? "" : msg;
                wrapped.log(systemLevel, bundle, String.format("[%s %s] %s", sourceClass, sourceMethod, msg), thrown);
            }
        }
    } else {
        platformProxy.logrb(level, sourceClass, sourceMethod, bundle, msg, thrown);
    }
}
Also used : Level(java.lang.System.Logger.Level) PlatformLogger(sun.util.logging.PlatformLogger) PlatformLogger(sun.util.logging.PlatformLogger) Logger(java.lang.System.Logger)

Aggregations

Logger (java.lang.System.Logger)58 IOException (java.io.IOException)39 ArrayList (java.util.ArrayList)38 FileOutputStream (java.io.FileOutputStream)36 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)34 SAXException (org.xml.sax.SAXException)34 URISyntaxException (java.net.URISyntaxException)28 File (java.io.File)23 Element (com.maxprograms.xml.Element)22 Document (com.maxprograms.xml.Document)17 FileInputStream (java.io.FileInputStream)16 PlatformLogger (sun.util.logging.PlatformLogger)16 SAXBuilder (com.maxprograms.xml.SAXBuilder)14 XMLOutputter (com.maxprograms.xml.XMLOutputter)14 Catalog (com.maxprograms.xml.Catalog)13 BufferedReader (java.io.BufferedReader)13 InputStreamReader (java.io.InputStreamReader)11 Segmenter (com.maxprograms.segmenter.Segmenter)7 Level (java.lang.System.Logger.Level)7 HashMap (java.util.HashMap)5