Skip to content

Commit

Permalink
Triple audit logging fix (#1995) (#1996)
Browse files Browse the repository at this point in the history
Revert some changes introduced by #1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
(cherry picked from commit 68f5624)
  • Loading branch information
jchipmunk authored and github-actions[bot] committed Aug 12, 2022
1 parent 46fd8a2 commit aeaa540
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/main/java/org/opensearch/security/auditlog/sink/Log4JSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,17 @@ public Log4JSink(final String name, final Settings settings, final String settin
loggerName = settings.get( settingsPrefix + ".log4j.logger_name","sgaudit");
auditLogger = LogManager.getLogger(loggerName);
logLevel = Level.toLevel(settings.get(settingsPrefix + ".log4j.level","INFO").toUpperCase());
enabled = isLogLevelEnabled(auditLogger, logLevel);
enabled = auditLogger.isEnabled(logLevel);
}

public boolean isHandlingBackpressure() {
return !enabled; //no submit to thread pool if not enabled
}


public boolean doStore(final AuditMessage msg) {
if(enabled) {
logAtLevel(auditLogger, logLevel, msg.toJson());
auditLogger.log(logLevel, msg.toJson());
}
return true;
}

private boolean isLogLevelEnabled(Logger logger, Level level) {
boolean isEnabled = false;
switch(level.toString()) {
case "TRACE": isEnabled = logger.isTraceEnabled();
case "DEBUG": isEnabled = logger.isDebugEnabled();
case "INFO": isEnabled = logger.isInfoEnabled();
case "WARN": isEnabled = logger.isWarnEnabled();
case "ERROR": isEnabled = logger.isErrorEnabled();
}
return isEnabled;
}

private void logAtLevel(Logger logger, Level level, String msg) {
switch(level.toString()) {
case "TRACE": logger.trace(msg);
case "DEBUG": logger.debug(msg);
case "INFO": logger.info(msg);
case "WARN": logger.warn(msg);
case "ERROR": logger.error(msg);
}
}
}

0 comments on commit aeaa540

Please sign in to comment.