All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdeploy.common.audit.Slf4jAuditor Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.4.0
Show newest version
package io.bdeploy.common.audit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
 * A {@linkplain Auditor auditor} implementation that is using a logger to write the audit records.
 */
public class Slf4jAuditor implements Auditor {

    private static final Logger log = LoggerFactory.getLogger(Slf4jAuditor.class);

    @Override
    public void close() {
        // nothing to close
    }

    @Override
    public void audit(AuditRecord rec) {
        MDC.put("WHO", rec.who);
        MDC.put("WHAT", rec.what);
        MDC.put("PARAMETERS", rec.parameters);
        MDC.put("METHOD", rec.method);

        switch (rec.severity) {
            case NORMAL:
                log.info(rec.message);
                break;
            case WARNING:
                log.warn(rec.message);
                break;
            case ERROR:
                log.error(rec.message);
                break;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy