package org.xbib.logging.filters;

import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 * A filter which modifies the log record with a new level if the nested filter evaluates {@code true} for that
 * record.
 */
public final class LevelChangingFilter implements Filter {

    private final Level newLevel;

    /**
     * Construct a new instance.
     *
     * @param newLevel the level to change to
     */
    public LevelChangingFilter(final Level newLevel) {
        this.newLevel = newLevel;
    }

    /**
     * Apply the filter to this log record.
     *
     * @param record the record to inspect and possibly update
     * @return {@code true} always
     */
    @Override
    public boolean isLoggable(final LogRecord record) {
        record.setLevel(newLevel);
        return true;
    }
}
