public Slf4jLog4j2AdapterActivateOption(Object logger) { super(null); try { org.apache.logging.log4j.core.Logger log4j2Logger = (org.apache.logging.log4j.core.Logger)loggerField.get( logger); super.logger = log4j2Logger; super.configuration = super.logger.getContext().getConfiguration(); } catch (Exception e) { throw new RuntimeException("logger must be instanceof org.apache.logging.slf4j.Log4jLogger", e); } }
public Log4j2ActivateOption(org.apache.logging.log4j.Logger logger) { if (logger != null) { if (logger instanceof org.apache.logging.log4j.core.Logger) { this.logger = (org.apache.logging.log4j.core.Logger)logger; configuration = this.logger.getContext().getConfiguration(); } else { throw new RuntimeException( "logger must instanceof org.apache.logging.log4j.core.Logger, " + logger.getClass().getName()); } } }
private static LoggerContext getRootLoggerContext() { return ((Logger) LogManager.getRootLogger()).getContext(); }
public LoggerContext getLoggerContext() { return getLogger().getContext(); }
/** {@inheritDoc} */ @Override public void setNodeId(UUID nodeId) { A.notNull(nodeId, "nodeId"); this.nodeId = nodeId; // Set nodeId as system variable to be used at configuration. System.setProperty(NODE_ID, U.id8(nodeId)); if (inited) { final LoggerContext ctx = impl.getContext(); synchronized (mux) { inited = false; } addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { if (init) ctx.reconfigure(); return (Logger)LogManager.getRootLogger(); } }); } }
/** * Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used * later to scan for suspect strings. The pattern of the messages conforms to the original log * format so that hydra will be able to parse them. */ private static void addSuspectFileAppender(final String workspaceDir) { final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath(); final LoggerContext appenderContext = ((org.apache.logging.log4j.core.Logger) LogManager .getLogger(Configuration.MAIN_LOGGER_NAME)) .getContext(); final PatternLayout layout = PatternLayout.createLayout( "[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n", null, null, null, Charset.defaultCharset(), true, false, "", ""); final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false", DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null, appenderContext.getConfiguration()); fileAppender.start(); LoggerConfig loggerConfig = appenderContext.getConfiguration().getLoggerConfig(Configuration.MAIN_LOGGER_NAME); loggerConfig.addAppender(fileAppender, Level.INFO, null); }
public LoggerConfig getLoggerConfig() { final Logger logger = getLogger(); final LoggerContext context = logger.getContext(); return context.getConfiguration().getLoggerConfig(logger.getName()); }
@Test public void testMultipleClassLoaders() throws Exception { final Class<?> logging1 = loader1.loadClass(PKG + ".a.Logging1"); final Field field1 = logging1.getDeclaredField("logger"); final Logger logger1 = (Logger) ReflectionUtil.getStaticFieldValue(field1); assertNotNull(logger1); final Class<?> logging2 = loader2.loadClass(PKG + ".b.Logging2"); final Field field2 = logging2.getDeclaredField("logger"); final Logger logger2 = (Logger) ReflectionUtil.getStaticFieldValue(field2); assertNotNull(logger2); final Class<?> logging3 = loader3.loadClass(PKG + ".c.Logging3"); final Field field3 = logging3.getDeclaredField("logger"); final Logger logger3 = (Logger) ReflectionUtil.getStaticFieldValue(field3); assertNotNull(logger3); assertNotSame(logger1.getContext(), logger2.getContext()); assertNotSame(logger1.getContext(), logger3.getContext()); assertNotSame(logger2.getContext(), logger3.getContext()); } }
@Override public void setLevel(Level level) { this.level = level; org.apache.logging.log4j.Level l = org.apache.logging.log4j.Level.toLevel(level.getName(), org.apache.logging.log4j.Level.ERROR); logger.setLevel(l); logger.getContext().getConfiguration().getLoggerConfig(this.logger.getName()).setLevel(l); }
/** * Creates console appender with some reasonable default logging settings. * * @return Logger with auto configured console appender. */ public Logger createConsoleLogger() { // from http://logging.apache.org/log4j/2.x/manual/customconfig.html final LoggerContext ctx = impl.getContext(); final Configuration cfg = ctx.getConfiguration(); PatternLayout.Builder builder = PatternLayout.newBuilder() .withPattern("%d{ISO8601}][%-5p][%t][%c{1}] %m%n") .withCharset(Charset.defaultCharset()) .withAlwaysWriteExceptions(false) .withNoConsoleNoAnsi(false); PatternLayout layout = builder.build(); ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder() .withName(CONSOLE_APPENDER) .withLayout(layout); ConsoleAppender consoleApp = consoleAppenderBuilder.build(); consoleApp.start(); cfg.addAppender(consoleApp); cfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null); ctx.updateLoggers(cfg); return ctx.getRootLogger(); }
@Override public LoggerContext getContext() { return getLogger().getContext(); }
this.rootLogger.removeAppender(appender); final Configuration configuration = rootLogger.getContext().getConfiguration();
this.rootLogger.removeAppender(appender); final Configuration configuration = rootLogger.getContext().getConfiguration();
this.rootLogger.removeAppender(appender); final Configuration configuration = rootLogger.getContext().getConfiguration();
this.rootLogger.removeAppender(appender); final Configuration configuration = rootLogger.getContext().getConfiguration();
public Log4j2ActivateOption(org.apache.logging.log4j.Logger logger) { if (logger != null) { if (logger instanceof org.apache.logging.log4j.core.Logger) { this.logger = (org.apache.logging.log4j.core.Logger) logger; configuration = this.logger.getContext().getConfiguration(); } else { throw new RuntimeException("logger must instanceof org.apache.logging.log4j.core.Logger, " + logger.getClass().getName()); } } }
public Log4j2ActivateOption(org.apache.logging.log4j.Logger logger) { if (logger != null) { if (logger instanceof org.apache.logging.log4j.core.Logger) { this.logger = (org.apache.logging.log4j.core.Logger)logger; configuration = this.logger.getContext().getConfiguration(); } else { throw new RuntimeException( "logger must instanceof org.apache.logging.log4j.core.Logger, " + logger.getClass().getName()); } } }
public static boolean isUsingGemFireDefaultConfig() { final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration(); final StrSubstitutor sub = config.getStrSubstitutor(); final StrLookup resolver = sub.getVariableResolver(); final String value = resolver.lookup(GEMFIRE_DEFAULT_PROPERTY); return "true".equals(value); }
public final Category getParent() { org.apache.logging.log4j.core.Logger parent = logger.getParent(); if (parent == null) { return null; } ConcurrentMap<String, Logger> loggers = getLoggersMap(logger.getContext()); Logger l = loggers.get(parent.getName()); return l == null ? new Category(parent) : l; }
@Override public void setLevel(Level level) { this.level = level; org.apache.logging.log4j.Level l = org.apache.logging.log4j.Level.toLevel(level.getName(), org.apache.logging.log4j.Level.ERROR); logger.setLevel(l); logger.getContext().getConfiguration().getLoggerConfig(this.logger.getName()).setLevel(l); }