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

org.jboss.logmanager.errormanager.HandlerErrorManager Maven / Gradle / Ivy

The newest version!
package org.jboss.logmanager.errormanager;

import java.util.logging.Handler;

import org.jboss.logmanager.ExtErrorManager;

import io.smallrye.common.constraint.Assert;

/**
 * An error manager which publishes errors to a handler.
 */
public final class HandlerErrorManager extends ExtErrorManager {
    private static final ThreadLocal handlingError = new ThreadLocal<>();

    private final Handler handler;

    /**
     * Construct a new instance.
     *
     * @param handler the handler to set (must not be {@code null})
     */
    public HandlerErrorManager(final Handler handler) {
        Assert.checkNotNullParam("handler", handler);
        this.handler = handler;
    }

    public void error(final String msg, final Exception ex, final int code) {
        if (handlingError.get() != Boolean.TRUE) {
            handlingError.set(Boolean.TRUE);
            try {
                handler.publish(errorToLogRecord(msg, ex, code));
            } finally {
                handlingError.remove();
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy