use of com.adeptj.runtime.tools.logging.LogbackConfig in project adeptj-modules by AdeptJ.
the class LoggingConfigFactory method start.
@Activate
protected void start(LoggingConfig config) {
String level = config.level();
String logFile = config.logFile();
String[] loggerNames = config.loggerNames();
boolean additivity = config.additivity();
LogbackManager logbackMgr = LogbackManager.INSTANCE;
// If configuration is for error.log, add the configured loggers to both FILE and CONSOLE appender.
if (StringUtils.endsWith(logFile, DEFAULT_LOG_FILE)) {
logbackMgr.addLogger(LogbackConfig.builder().loggers(loggerNames).level(level).additivity(additivity).appenders(logbackMgr.getAppenders()).build());
return;
}
// If no log file provided then add the configured loggers only to CONSOLE appender.
if (StringUtils.endsWith(logFile, SLASH)) {
logbackMgr.addLogger(LogbackConfig.builder().loggers(loggerNames).level(level).additivity(additivity).appender(logbackMgr.getAppender(APPENDER_CONSOLE)).build());
return;
}
String rolloverFile = config.rolloverFile();
String pattern = config.pattern();
int logMaxHistory = config.logMaxHistory();
String logMaxSize = config.logMaxSize();
boolean immediateFlush = config.immediateFlush();
boolean addAsyncAppender = config.addAsyncAppender();
int asyncLogQueueSize = config.asyncLogQueueSize();
int asyncLogDiscardingThreshold = config.asyncLogDiscardingThreshold();
LogbackConfig logbackConfig = LogbackConfig.builder().appenderName(UUID.randomUUID().toString()).asyncAppenderName(UUID.randomUUID().toString()).level(level).logFile(logFile).additivity(additivity).rolloverFile(rolloverFile).pattern(pattern).logMaxHistory(logMaxHistory).logMaxSize(logMaxSize).immediateFlush(immediateFlush).addAsyncAppender(addAsyncAppender).asyncLogQueueSize(asyncLogQueueSize).asyncLogDiscardingThreshold(asyncLogDiscardingThreshold).loggers(loggerNames).build();
RollingFileAppender<ILoggingEvent> fileAppender = logbackMgr.createRollingFileAppender(logbackConfig);
logbackConfig.getAppenders().add(fileAppender);
if (logbackConfig.isAddAsyncAppender()) {
logbackConfig.setAsyncAppender(fileAppender);
logbackMgr.addAppender(fileAppender).createAsyncAppender(logbackConfig);
}
logbackMgr.addLogger(logbackConfig);
}
use of com.adeptj.runtime.tools.logging.LogbackConfig in project adeptj-runtime by AdeptJ.
the class LogbackInitializer method init.
public static void init() {
long startTime = System.nanoTime();
Config loggingCfg = Configs.DEFAULT.logging();
LogbackConfig logbackConfig = getLogbackConfig(loggingCfg);
LogbackManager logbackMgr = LogbackManager.INSTANCE;
RollingFileAppender<ILoggingEvent> fileAppender = logbackMgr.createRollingFileAppender(logbackConfig);
ConsoleAppender<ILoggingEvent> consoleAppender = logbackMgr.createConsoleAppender(APPENDER_CONSOLE, loggingCfg.getString(KEY_LOG_PATTERN_CONSOLE));
List<Appender<ILoggingEvent>> appenderList = new ArrayList<>();
appenderList.add(consoleAppender);
appenderList.add(fileAppender);
logbackMgr.getAppenders().addAll(appenderList);
LoggerContext context = logbackMgr.getLoggerContext();
initRootLogger(context, consoleAppender, loggingCfg);
addLoggers(loggingCfg, appenderList);
addAsyncAppender(loggingCfg, fileAppender);
context.start();
context.getLogger(LogbackInitializer.class).info(INIT_MSG, elapsedMillis(startTime));
}
Aggregations