AbstractBackend extends LoggerBackend { void log(LogRecord record, boolean wasForced) { if (!wasForced || logger.isLoggable(record.getLevel())) { logger.log(record); } else { Filter filter = logger.getFilter(); if (filter != null) { filter.isLoggable(record); } if (logger.getClass() == Logger.class || cannotUseForcingLogger) { publish(logger, record); } else { forceLoggingViaChildLogger(record); } } } AbstractBackend(Logger logger); @Override final String getLoggerName(); @Override final boolean isLoggable(Level lvl);  }
@Test public void testUnforcedLoggingCallsLoggerDirectly() { TestLogger logger = new TestLogger("loggy.mclogface", Level.INFO); TestBackend backend = new TestBackend(logger); backend.log(new LogRecord(Level.INFO, "Enabled"), false ); logger.assertLogged("Enabled"); logger.assertPublished("Enabled"); backend.assertUsedForcingLogger(false); backend.log(new LogRecord(Level.FINE, "Disabled"), false ); logger.assertLogged("Disabled"); logger.assertPublished(null); backend.assertUsedForcingLogger(false); }
@Test public void testForcedLoggingBypassesLoggerIfNeeded() { TestLogger logger = new TestLogger("loggy.mclogface", Level.INFO); TestBackend backend = new TestBackend(logger); backend.log(new LogRecord(Level.INFO, "Enabled and Forced"), true ); logger.assertLogged("Enabled and Forced"); logger.assertPublished("Enabled and Forced"); backend.assertUsedForcingLogger(false); backend.log(new LogRecord(Level.FINE, "Disabled and Forced"), true ); logger.assertLogged(null); logger.assertPublished("Disabled and Forced"); backend.assertUsedForcingLogger(true); }