use of org.apache.syncope.core.logic.MemoryAppender in project syncope by apache.
the class LoggerLoader method load.
@Override
public void load() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.getConfiguration().getAppenders().entrySet().stream().filter(entry -> (entry.getValue() instanceof MemoryAppender)).forEachOrdered(entry -> {
memoryAppenders.put(entry.getKey(), (MemoryAppender) entry.getValue());
});
// Audit table and DataSource for each configured domain
ColumnConfig[] columnConfigs = { ColumnConfig.newBuilder().setConfiguration(ctx.getConfiguration()).setName("EVENT_DATE").setEventTimestamp(true).build(), ColumnConfig.newBuilder().setUnicode(false).setConfiguration(ctx.getConfiguration()).setName("LOGGER_LEVEL").setPattern("%level").build(), ColumnConfig.newBuilder().setUnicode(false).setConfiguration(ctx.getConfiguration()).setName("LOGGER").setPattern("%logger").build(), ColumnConfig.newBuilder().setUnicode(false).setConfiguration(ctx.getConfiguration()).setName("MESSAGE").setPattern("%message").build(), ColumnConfig.newBuilder().setUnicode(false).setConfiguration(ctx.getConfiguration()).setName("THROWABLE").setPattern("%ex{full}").build() };
ColumnMapping[] columnMappings = new ColumnMapping[0];
for (Map.Entry<String, DataSource> entry : domainsHolder.getDomains().entrySet()) {
Appender appender = ctx.getConfiguration().getAppender("audit_for_" + entry.getKey());
if (appender == null) {
appender = JdbcAppender.newBuilder().withName("audit_for_" + entry.getKey()).withIgnoreExceptions(false).setConnectionSource(new DataSourceConnectionSource(entry.getKey(), entry.getValue())).setBufferSize(0).setTableName("SYNCOPEAUDIT").setColumnConfigs(columnConfigs).setColumnMappings(columnMappings).build();
appender.start();
ctx.getConfiguration().addAppender(appender);
}
LoggerConfig logConf = new LoggerConfig(AuditLoggerName.getAuditLoggerName(entry.getKey()), null, false);
logConf.addAppender(appender, Level.DEBUG, null);
logConf.setLevel(Level.DEBUG);
ctx.getConfiguration().addLogger(AuditLoggerName.getAuditLoggerName(entry.getKey()), logConf);
// SYNCOPE-1144 For each custom audit appender class add related appenders to log4j logger
auditAppenders(entry.getKey()).forEach(auditAppender -> {
auditAppender.getEvents().stream().map(event -> AuditLoggerName.getAuditEventLoggerName(entry.getKey(), event.toLoggerName())).forEachOrdered(domainAuditLoggerName -> {
LoggerConfig eventLogConf = ctx.getConfiguration().getLoggerConfig(domainAuditLoggerName);
if (LogManager.ROOT_LOGGER_NAME.equals(eventLogConf.getName())) {
eventLogConf = new LoggerConfig(domainAuditLoggerName, null, false);
}
addAppenderToContext(ctx, auditAppender, eventLogConf);
eventLogConf.setLevel(Level.DEBUG);
if (LogManager.ROOT_LOGGER_NAME.equals(eventLogConf.getName())) {
ctx.getConfiguration().addLogger(domainAuditLoggerName, eventLogConf);
}
});
});
AuthContextUtils.execWithAuthContext(entry.getKey(), () -> {
loggerAccessor.synchronizeLog4J(ctx);
return null;
});
}
ctx.updateLoggers();
}
Aggregations