我正在尝试使用log4j记录我的应用程序操作,将日志输出到文件和控制台 它是一个使用Spring Boot的基于Web的应用程序。 当我运行应用程序时,初始日志将写入文件中,但是启动后的任何后续调用都不会写入文件中,而是会在控制台中输出。 这是log4jproperties的代码:
appenders = console, rolling
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.rolling.type=RollingFile
appender.rolling.name=ROLLING
appender.rolling.filePattern=src/main/resources/logs/service-%d{yyyy-MM-dd}.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
rootLogger.level = info
rootLogger.appenderRefs = stdout, rolling
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.rolling.ref = ROLLING
这是我运行的应用程序类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
private static final Logger LOGGER =
LogManager.getLogger(Application.class.getName());
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
AsynchronousScreenListenersNotifier.addListener(new SimulatorListener());
LOGGER.info("------------ Server Started ------------ ");
SpringApplication.run(Application.class, args);
}
}
来自另一个类的标准调用:
public class Validator {
private static final Logger LOGGER = LogManager.getLogger(Validator.class.getName());
public static List<Receiver> validate(Circuit circuit)
{
if (circuit.getGenerator() == null || circuit.getReceivers() == null || circuit.getReceivers().isEmpty()) {
LOGGER.info("Validator Received Empty Circuit");
return newArrayList();
}