001// Generated by delombok at Sat Feb 25 17:58:34 UTC 2023
002package io.cui.tools.logging;
003
004import static io.cui.tools.reflect.MoreReflection.findCaller;
005import java.util.Set;
006import java.util.function.Supplier;
007import io.cui.tools.collect.CollectionLiterals;
008
009/**
010 * Class provide factory method for CuiLogger instance
011 */
012public final class CuiLoggerFactory {
013    static final Set<String> MARKER_CLASS_NAMES = CollectionLiterals.immutableSet(CuiLogger.class.getName(), CuiLoggerFactory.class.getName());
014    private static final Supplier<IllegalStateException> ILLEGAL_STATE_EXCEPTION_SUPPLIER = () -> new IllegalStateException("Unable to detect caller class name. Make sure \'" + MARKER_CLASS_NAMES + "\' was used for creation.");
015
016    /**
017     * Automatic determine the caller class.
018     *
019     * @return {@link CuiLogger}
020     * @throws IllegalStateException if caller couldn't be detected
021     */
022    public static CuiLogger getLogger() {
023        return getLogger(findCaller(MARKER_CLASS_NAMES).orElseThrow(ILLEGAL_STATE_EXCEPTION_SUPPLIER));
024    }
025
026    /**
027     * Create logger and use the hand-over class name as logger name
028     *
029     * @param className must not be null
030     * @return {@link CuiLogger}
031     */
032    public static CuiLogger getLogger(final String className) {
033        return new CuiLogger(className);
034    }
035
036    /**
037     * Create logger and use the hand-over class name as logger name
038     *
039     * @param clazz must not be null
040     * @return {@link CuiLogger}
041     */
042    public static CuiLogger getLogger(final Class<?> clazz) {
043        return new CuiLogger(clazz);
044    }
045
046    @java.lang.SuppressWarnings("all")
047    @lombok.Generated
048    private CuiLoggerFactory() {
049        throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
050    }
051}