loggerLogs.put(syncopeLogger.getName(), syncopeLogger);
}
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
LoggerContext lc = (LoggerContext) loggerFactory;
/*
* Traverse all defined Logback loggers: if there is a matching SyncopeLogger, set Logback level accordingly,
* otherwise create a SyncopeLogger instance with given name and level.
*/
for (Logger logger : lc.getLoggerList()) {
if (logger.getLevel() != null) {
if (loggerLogs.containsKey(logger.getName())) {
logger.setLevel(loggerLogs.get(logger.getName()).getLevel().getLevel());
loggerLogs.remove(logger.getName());
} else if (!logger.getName().equals(SyncopeLoggerType.AUDIT.getPrefix())) {
SyncopeLogger syncopeLogger = new SyncopeLogger();
syncopeLogger.setName(logger.getName());
syncopeLogger.setLevel(SyncopeLoggerLevel.fromLevel(logger.getLevel()));
syncopeLogger.setType(logger.getName().startsWith(SyncopeLoggerType.AUDIT.getPrefix())
? SyncopeLoggerType.AUDIT
: SyncopeLoggerType.LOG);
loggerDAO.save(syncopeLogger);
}
}
}
/*
* Foreach SyncopeLogger not found in Logback, create a new Logback logger with given name and level.
*/
for (SyncopeLogger syncopeLogger : loggerLogs.values()) {
Logger logger = lc.getLogger(syncopeLogger.getName());
logger.setLevel(syncopeLogger.getLevel().getLevel());
}
}