Java Code Examples for org.apache.logging.log4j.core.Appender#isStarted()
The following examples show how to use
org.apache.logging.log4j.core.Appender#isStarted() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogFactory.java From chronus with Apache License 2.0 | 5 votes |
private Appender getAppender(LogConfig abyLogConfig, Configuration config, Appender appenderCfg) { Appender appender = null; if (appenderCfg instanceof RollingFileAppender) { RollingFileAppender rollingFileAppender = (RollingFileAppender) appenderCfg; appender = RollingFileAppender.newBuilder() .setConfiguration(config) .withName(appenderCfg.getName().replace(abyLogConfig.getAppenderNameKey(), abyLogConfig.getName())) .withFileName(rollingFileAppender.getFileName().replaceAll(abyLogConfig.getFileNameKey(), abyLogConfig.getFileName())) .withFilePattern(rollingFileAppender.getFilePattern().replaceAll(abyLogConfig.getFileNameKey(), abyLogConfig.getFileName())) .withLayout(rollingFileAppender.getLayout()) .withFilter(rollingFileAppender.getFilter()) .withPolicy(rollingFileAppender.getTriggeringPolicy()) .withStrategy(rollingFileAppender.getManager().getRolloverStrategy()) .build(); } else if (appenderCfg instanceof FileAppender) { FileAppender fileAppender = (FileAppender) appenderCfg; appender = FileAppender.newBuilder() .setConfiguration(config) .withName(appenderCfg.getName().replace(abyLogConfig.getAppenderNameKey(), abyLogConfig.getName())) .withFileName(fileAppender.getFileName().replaceAll(abyLogConfig.getFileNameKey(), abyLogConfig.getFileName())) .withLayout(fileAppender.getLayout()) .withFilter(fileAppender.getFilter()) .build(); } else { LogManager.getLogger(LogFactory.class).warn("unsupported appender type ,appender type not in(RollingFileAppender,ConsoleAppender,FileAppender)", appenderCfg.getClass()); } if (appender != null) { if (!appender.isStarted()) { appender.start(); } config.addAppender(appender); } return appender; }
Example 2
Source File: BaseService.java From support-diagnostics with Apache License 2.0 | 5 votes |
protected void createFileAppender(String logDir, String logFile) { logPath = logDir + SystemProperties.fileSeparator + logFile; Layout layout = PatternLayout.newBuilder() .withConfiguration(logConfig) .withPattern("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n") .build(); FileAppender.Builder builder = FileAppender.newBuilder(); builder.setConfiguration(logConfig); builder.withFileName(logPath); builder.withAppend(false); builder.withLocking(false); builder.setName("packaged"); builder.setIgnoreExceptions(false); builder.withImmediateFlush(true); builder.withBufferedIo(false); builder.withBufferSize(0); builder.setLayout(layout); Appender diagAppender = builder.build(); Appender oldAppender = logConfig.getAppender("packaged"); if(oldAppender != null && oldAppender.isStarted()){ oldAppender.stop(); logConfig.getRootLogger().removeAppender("packaged"); } diagAppender.start(); logConfig.addAppender(diagAppender); AppenderRef.createAppenderRef("packaged", null, null); logConfig.getRootLogger().addAppender(diagAppender, null, null); loggerContext.updateLoggers(); logger.info(Constants.CONSOLE, "Diagnostic logger reconfigured for inclusion into archive"); }
Example 3
Source File: BaseService.java From support-diagnostics with Apache License 2.0 | 3 votes |
protected void closeLogs() { logger.info(Constants.CONSOLE, "Closing loggers."); Appender appndr = logConfig.getAppender("diag"); if(appndr != null && appndr.isStarted()){ appndr.stop(); } logConfig.getRootLogger().removeAppender("File"); }