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

cool.scx.logging.ScxLoggerConfig Maven / Gradle / Ivy

There is a newer version: 2.7.4
Show newest version
package cool.scx.logging;

import java.util.HashSet;
import java.util.Set;

import static java.lang.System.Logger.Level;
import static java.util.Collections.addAll;

/**
 * ScxLoggerConfig
 *
 * @author scx567888
 * @version 2.0.8
 */
public class ScxLoggerConfig {

    private final ScxLoggerConfig parent;

    private Level level = null;

    private Boolean stackTrace = null;

    private Set recorders = null;

    public ScxLoggerConfig(ScxLoggerConfig parent) {
        this.parent = parent;
    }

    public final Level level() {
        return level != null ? level : parent != null ? parent.level() : Level.ERROR;
    }

    public final Boolean stackTrace() {
        return stackTrace != null ? stackTrace : parent != null ? parent.stackTrace() : false;
    }

    public final Set recorders() {
        return recorders != null ? recorders : parent != null ? parent.recorders() : new HashSet<>();
    }

    public final ScxLoggerConfig setLevel(Level newLevel) {
        this.level = newLevel;
        return this;
    }

    public final ScxLoggerConfig setStackTrace(Boolean newStackTrace) {
        this.stackTrace = newStackTrace;
        return this;
    }

    public final ScxLoggerConfig addRecorder(ScxLogRecorder recorder, ScxLogRecorder... recorders) {
        if (this.recorders == null) {
            this.recorders = new HashSet<>();
        }
        this.recorders.add(recorder);
        addAll(this.recorders, recorders);
        return this;
    }

    public final ScxLoggerConfig removeRecorder(ScxLogRecorder recorder) {
        if (this.recorders != null) {
            this.recorders.remove(recorder);
        }
        return this;
    }

    public final ScxLoggerConfig clearRecorders() {
        this.recorders = null;
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy