private static LoggerContext configureContext(LoggerContext context, Map<String, String> substitutionVariables) { context.reset(); for (Map.Entry<String, String> entry : substitutionVariables.entrySet()) { context.putProperty(entry.getKey(), entry.getValue()); } return context; }
@Override protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) { LoggerContext context = getLoggerContext(); stopAndReset(context); LogbackConfigurator configurator = new LogbackConfigurator(context); Environment environment = initializationContext.getEnvironment(); context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN, environment.resolvePlaceholders( "${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}")); context.putProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, environment.resolvePlaceholders( "${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}")); new DefaultLogbackConfiguration(initializationContext, logFile) .apply(configurator); context.setPackagingDataEnabled(true); }
private LoggerContext getLoggerContext(Map<String, String> props) { ILoggerFactory lcObject = LoggerFactory.getILoggerFactory(); if (!(lcObject instanceof LoggerContext)) { throw new LogbackException( "Expected LOGBACK binding with SLF4J, but another log system has taken the place: " + lcObject.getClass().getSimpleName()); } LoggerContext lc = (LoggerContext) lcObject; lc.reset(); for (Map.Entry<String, String> entry : props.entrySet()) { lc.putProperty(entry.getKey(), entry.getValue()); } return lc; }
private LoggerContext getLoggerContext(Map<String, String> props) { ILoggerFactory lcObject = LoggerFactory.getILoggerFactory(); if (!(lcObject instanceof LoggerContext)) { throw new LogbackException( "Expected LOGBACK binding with SLF4J, but another log system has taken the place: " + lcObject.getClass().getSimpleName()); } LoggerContext lc = (LoggerContext) lcObject; lc.reset(); for (Map.Entry<String, String> entry : props.entrySet()) { lc.putProperty(entry.getKey(), entry.getValue()); } return lc; }
private LoggerContext getLoggerContext(Map<String, String> props) { ILoggerFactory lcObject = LoggerFactory.getILoggerFactory(); if (!(lcObject instanceof LoggerContext)) { throw new LogbackException( "Expected LOGBACK binding with SLF4J, but another log system has taken the place: " + lcObject.getClass().getSimpleName()); } LoggerContext lc = (LoggerContext) lcObject; lc.reset(); for (Map.Entry<String, String> entry : props.entrySet()) { lc.putProperty(entry.getKey(), entry.getValue()); } return lc; }
private void initProperties(LoggerContext loggerContext, Properties properties) { for (Map.Entry entry : properties.entrySet()) { String key = (String) entry.getKey(); String originValue = (String) entry.getValue(); String value = System.getProperty(key, originValue); loggerContext.putProperty(key, value); } } }
private static LoggerContext configureContext(LoggerContext context, Map<String, String> substitutionVariables) { context.reset(); for (Map.Entry<String, String> entry : substitutionVariables.entrySet()) { context.putProperty(entry.getKey(), entry.getValue()); } return context; }
private void setClassQualifiedTestName(final String name) { final LoggerContext loggerContext = ((ch.qos.logback.classic.Logger) LOGGER).getLoggerContext(); loggerContext.putProperty(LogbackPropertyValueDiscriminator.CLASS_QUALIFIED_TEST_NAME, name); }
@Override public void onReset(LoggerContext ctx) { for (String prop : propsToAdd.stringPropertyNames()) { ctx.putProperty(prop, propsToAdd.getProperty(prop)); } System.out.println("LoggerContext reset, current properties: " + ctx.getCopyOfPropertyMap()); }
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); context.reset(); // override default configuration // inject the name of the current application as "application-name" // property of the LoggerContext context.putProperty("application-name", NAME_OF_CURRENT_APPLICATION); jc.doConfigure("/path/to/the/above/configuration/file.xml");
@Test public void shutdownHookTest() throws JoranException { String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + "issues/logback_1162.xml"; loggerContext.putProperty("output_dir", ClassicTestConstants.OUTPUT_DIR_PREFIX + "logback_issue_1162/"); configure(configFileAsStr); assertNotNull(loggerContext.getObject(CoreConstants.SHUTDOWN_HOOK_THREAD)); } }
@Test public void resetTest_LBCORE_104() { lc.putProperty("keyA", "valA"); lc.putObject("keyA", "valA"); assertEquals("valA", lc.getProperty("keyA")); assertEquals("valA", lc.getObject("keyA")); lc.reset(); assertNull(lc.getProperty("keyA")); assertNull(lc.getObject("keyA")); }
void configure(String file) throws JoranException { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(loggerContext); loggerContext.putProperty("diff", "" + diff); jc.doConfigure(file); }
@Before @Override public void setUp() throws ParseException { lc.setName("test"); super.setUp(); lc.putProperty("randomOutputDir", randomOutputDir); }
@Test public void depratedSizeAndTimeBasedFNATPWarning() throws Exception { String testId = "depratedSizeAndTimeBasedFNATPWarning"; lc.putProperty("testId", testId); loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "rolling/" + testId + ".xml"); statusChecker.assertContainsMatch(Status.WARN, CoreConstants.SIZE_AND_TIME_BASED_FNATP_IS_DEPRECATED); }
private void configure(int port, String file) throws JoranException { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(loggerContext); loggerContext.putProperty("port", "" + port); jc.doConfigure(file); }
@Test public void contextProperty() { pl.setPattern("%property{a}"); pl.start(); lc.putProperty("a", "b"); String val = pl.doLayout(getEventObject()); assertEquals("b", val); }
public void immediateFlushInEncoder(Boolean immediateFlush) throws JoranException { loggerContext.putProperty("immediateFlush", immediateFlush.toString()); jc.doConfigure(ClassicTestConstants.JORAN_INPUT_PREFIX + "compatibility/immediateFlushInEncoder.xml"); StatusPrinter.print(loggerContext); StatusChecker checker = new StatusChecker(loggerContext); checker.assertContainsMatch(Status.WARN, "As of version 1.2.0 \"immediateFlush\" property should be set within the enclosing Appender."); checker.assertContainsMatch(Status.WARN, "Please move \"immediateFlush\" property into the enclosing appender."); checker.assertContainsMatch(Status.WARN, "Setting the \"immediateFlush\" property of the enclosing appender to " + immediateFlush); ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) root.getAppender("LIOE"); assertTrue(fileAppender.isStarted()); assertEquals(immediateFlush.booleanValue(), fileAppender.isImmediateFlush()); } }
@Test public void totalSizeCapSmallerThanMaxFileSize() throws Exception { String testId = "totalSizeCapSmallerThanMaxFileSize"; lc.putProperty("testId", testId); loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "rolling/" + testId + ".xml"); Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME); //expectedFilenameList.add(randomOutputDir + "z" + testId); RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root.getAppender("ROLLING"); statusChecker.assertContainsMatch("totalSizeCap of \\[\\d* \\w*\\] is smaller than maxFileSize \\[\\d* \\w*\\] which is non-sensical"); assertFalse(rfa.isStarted()); }
@Before public void setup() throws JoranException { config = new JoranConfigurator(); context = new LoggerContext(); context.putProperty("OUT_DIR", OUT_DIR); config.setContext(context); config.doConfigure(pathToConfig); }