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

io.github.sinri.keel.logger.event.KeelEventLoggerImpl Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

The newest version!
package io.github.sinri.keel.logger.event;

import io.github.sinri.keel.logger.KeelLogLevel;
import io.github.sinri.keel.logger.issue.recorder.KeelIssueRecorder;
import io.vertx.core.Handler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

/**
 * @since 3.2.0
 */
class KeelEventLoggerImpl implements KeelEventLogger {
    private final @Nonnull KeelIssueRecorder issueRecorder;
    private final @Nullable Handler templateEventLogEditor;
    private final @Nonnull List bypassLoggers;
    private @Nullable Handler dynamicFormatter;

    KeelEventLoggerImpl(@Nonnull KeelIssueRecorder issueRecorder, @Nullable Handler templateEventLogEditor) {
        this.issueRecorder = issueRecorder;
        this.templateEventLogEditor = templateEventLogEditor;
        this.bypassLoggers = new ArrayList<>();
    }

    @Nullable
    @Override
    public Handler templateEventLogEditor() {
        return templateEventLogEditor;
    }

    /**
     * @since 3.2.7
     */
    @Override
    public void setDynamicEventLogFormatter(@Nullable Handler formatter) {
        this.dynamicFormatter = formatter;
    }

    @Nonnull
    private KeelIssueRecorder getIssueRecorder() {
        return issueRecorder;
    }

    @Override
    public void addBypassLogger(@Nonnull KeelEventLogger bypassLogger) {
        this.bypassLoggers.add(bypassLogger);
    }

    @Nonnull
    @Override
    public List getBypassLoggers() {
        return bypassLoggers;
    }

    @Nonnull
    @Override
    public KeelLogLevel getVisibleLevel() {
        return this.getIssueRecorder().getVisibleLevel();
    }

    @Override
    public void setVisibleLevel(@Nonnull KeelLogLevel level) {
        this.getIssueRecorder().setVisibleLevel(level);
    }

    @Nonnull
    @Override
    public String getPresetTopic() {
        return this.getIssueRecorder().topic();
    }

    @Override
    public void log(@Nonnull Handler eventLogHandler) {
        Handler h = r -> {
            var x = templateEventLogEditor();
            if (x != null) {
                x.handle(r);
            }
            eventLogHandler.handle(r);
            // since 3.2.7
            if (dynamicFormatter != null) {
                dynamicFormatter.handle(r);
            }
        };

        this.getIssueRecorder().record(h);

        getBypassLoggers().forEach(bypassLogger -> {
            bypassLogger.log(h);
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy