public void apply(LogFile logFile) { RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver( this.environment, "logging."); setSystemProperty(propertyResolver, EXCEPTION_CONVERSION_WORD, "exception-conversion-word"); setSystemProperty(propertyResolver, CONSOLE_LOG_PATTERN, "pattern.console"); setSystemProperty(propertyResolver, FILE_LOG_PATTERN, "pattern.file"); setSystemProperty(propertyResolver, LOG_LEVEL_PATTERN, "pattern.level"); setSystemProperty(PID_KEY, new ApplicationPid().toString()); if (logFile != null) { logFile.applyToSystemProperties(); } }
@Test public void logFilePropertiesCanReferenceSystemProperties() { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "logging.file=target/${PID}.log"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); assertThat(System.getProperty("LOG_FILE")) .isEqualTo("target/" + new ApplicationPid().toString() + ".log"); }
private void writePidFile(SpringApplicationEvent event) throws IOException { File pidFile = this.file; String override = getProperty(event, FILE_PROPERTIES); if (override != null) { pidFile = new File(override); } new ApplicationPid().write(pidFile); pidFile.deleteOnExit(); }
/** * Initialize the logging system according to preferences expressed through the * {@link Environment} and the classpath. * @param environment the environment * @param classLoader the classloader */ protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) { if (System.getProperty(PID_KEY) == null) { System.setProperty(PID_KEY, new ApplicationPid().toString()); } if (System.getProperty(EXCEPTION_CONVERSION_WORD) == null) { System.setProperty(EXCEPTION_CONVERSION_WORD, getExceptionConversionWord(environment)); } initializeEarlyLoggingLevel(environment); initializeSystem(environment, this.loggingSystem); initializeFinalLoggingLevels(environment, this.loggingSystem); registerShutdownHookIfNecessary(environment, this.loggingSystem); }