Search in sources :

Example 6 with Level

use of java.lang.System.Logger.Level 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 7 with Level

use of java.lang.System.Logger.Level 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)

Example 8 with Level

use of java.lang.System.Logger.Level in project Tupl by cojen.

the class EventListenerTest method ignore.

@Test
public void ignore() throws Exception {
    var listener = new Listener();
    assertSame(listener, listener.ignore(new EventType.Category[0]));
    assertSame(listener, listener.ignore(new Level[0]));
    EventListener filtered = listener.ignore(EventType.Category.DEBUG);
    filtered.notify(EventType.DEBUG, "hello");
    filtered.notify(EventType.CHECKPOINT_BEGIN, "world");
    assertEquals("[CHECKPOINT_BEGIN:world:[]]", listener.mEvents.toString());
    assertSame(filtered, filtered.ignore(EventType.Category.DEBUG));
    listener = new Listener();
    filtered = listener.ignore(Level.DEBUG);
    filtered.notify(EventType.DEBUG, "hello");
    filtered.notify(EventType.CHECKPOINT_FAILED, "world");
    assertEquals("[CHECKPOINT_FAILED:world:[]]", listener.mEvents.toString());
    assertSame(filtered, filtered.ignore(Level.DEBUG));
    listener.mEvents.clear();
    filtered = filtered.ignore(Level.WARNING);
    filtered.notify(EventType.DEBUG, "hello");
    filtered.notify(EventType.CHECKPOINT_FAILED, "world");
    assertEquals("[]", listener.mEvents.toString());
    listener.mEvents.clear();
    filtered = filtered.observe(Level.WARNING);
    filtered.notify(EventType.DEBUG, "hello");
    filtered.notify(EventType.CHECKPOINT_FAILED, "world");
    assertEquals("[]", listener.mEvents.toString());
}
Also used : EventListener(org.cojen.tupl.diag.EventListener) Level(java.lang.System.Logger.Level) EventListener(org.cojen.tupl.diag.EventListener)

Aggregations

Level (java.lang.System.Logger.Level)8 Logger (java.lang.System.Logger)7 PlatformLogger (sun.util.logging.PlatformLogger)7 EventListener (org.cojen.tupl.diag.EventListener)1