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

io.quarkus.test.InMemoryLogHandler Maven / Gradle / Ivy

Go to download

A runner for unit tests, intended for testing Quarkus rather than for end user consumption.

There is a newer version: 3.17.5
Show newest version
package io.quarkus.test;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import org.jboss.logmanager.ExtHandler;
import org.wildfly.common.Assert;

public class InMemoryLogHandler extends ExtHandler {

    private final Predicate predicate;

    public InMemoryLogHandler(Predicate predicate) {
        this.predicate = Assert.checkNotNullParam("predicate", predicate);
    }

    final List records = new CopyOnWriteArrayList<>();

    @Override
    public void publish(LogRecord record) {
        if (predicate.test(record)) {
            records.add(record);
        }
    }

    @Override
    public void flush() {
    }

    @Override
    public Level getLevel() {
        return Level.FINE;
    }

    @Override
    public void close() throws SecurityException {
        this.records.clear();
    }

    public List getRecords() {
        return records;
    }

    void clearRecords() {
        this.records.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy