/*
 * Copyright 2016-2022 chronicle.software
 *
 *       https://chronicle.software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.openhft.chronicle.core.internal;

import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.onoes.ExceptionKey;
import net.openhft.chronicle.core.onoes.LogLevel;
import net.openhft.chronicle.testframework.internal.ExceptionTracker;

import java.util.EnumSet;
import java.util.Set;

import static net.openhft.chronicle.core.onoes.LogLevel.DEBUG;
import static net.openhft.chronicle.core.onoes.LogLevel.PERF;

/**
 * A Factory for creating ExceptionTrackers that use {@link Jvm} to track exceptions represented
 * by {@link ExceptionKey}s.
 */
public enum JvmExceptionTracker {
    ;

    private static final Set<LogLevel> IGNORED_LOG_LEVELS = EnumSet.of(DEBUG, PERF);

    /**
     * Create a JvmExceptionTracker
     *
     * @return the exception tracker
     */
    public static ExceptionTracker<ExceptionKey> create() {
        return ExceptionTracker.create(
                ExceptionKey::message,
                ExceptionKey::throwable,
                Jvm::resetExceptionHandlers,
                Jvm.recordExceptions(),
                key -> IGNORED_LOG_LEVELS.contains(key.level()),
                key -> key.level() + " " + key.clazz().getSimpleName() + " " + key.message()
        );
    }
}

@@ -928,16 +928,38 @@
 numSet;%0A
+import java.util.Map;%0A
 import j
@@ -972,16 +972,16 @@
 il.Set;%0A
-
 %0Aimport 
@@ -1516,16 +1516,1665 @@
 ate() %7B%0A
+        return create(Jvm.recordExceptions());%0A    %7D%0A%0A    /**%0A     * Create a JvmExceptionTracker%0A     *%0A     * @param debug Whether to track debug messages%0A     * @return the exception tracker%0A     */%0A    public static ExceptionTracker%3CExceptionKey%3E create(final boolean debug) %7B%0A        return create(Jvm.recordExceptions(debug));%0A    %7D%0A%0A    /**%0A     * Create a JvmExceptionTracker%0A     *%0A     * @param debug          Whether to track debug messages%0A     * @param exceptionsOnly Whether to track only messages with exceptions%0A     * @return the exception tracker%0A     */%0A    public static ExceptionTracker%3CExceptionKey%3E create(final boolean debug,%0A                                                        final boolean exceptionsOnly) %7B%0A        return create(Jvm.recordExceptions(debug, exceptionsOnly));%0A    %7D%0A%0A    /**%0A     * Create a JvmExceptionTracker%0A     *%0A     * @param debug          Whether to track debug messages%0A     * @param exceptionsOnly Whether to track only messages with exceptions%0A     * @param logToSlf4j     Whether to also log messages to slf4j%0A     * @return the exception tracker%0A     */%0A    public static ExceptionTracker%3CExceptionKey%3E create(final boolean debug,%0A                                                        final boolean exceptionsOnly,%0A                                                        final boolean logToSlf4j) %7B%0A        return create(Jvm.recordExceptions(debug, exceptionsOnly, logToSlf4j));%0A    %7D%0A%0A    /**%0A     * Create a JvmExceptionTracker%0A     *%0A     * @return the exception tracker%0A     */%0A    private static ExceptionTracker%3CExceptionKey%3E create(Map%3CExceptionKey, Integer%3E recordedExceptions) %7B%0A
         
@@ -3346,26 +3346,24 @@
         
-Jvm.
 record
+ed
 Exceptio
@@ -3364,18 +3364,16 @@
 ceptions
-()
 ,%0A      

Add parameters to JvmExceptionTracker.create