<commit_before>package org.jpos.util.slf4j;

import org.jpos.core.Configuration;
import org.jpos.util.Log;
import org.jpos.util.Logger;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

@SuppressWarnings("WeakerAccess")
public class JPOSLogger extends MarkerIgnoringBase
{
    private Log log;

    private static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
    private static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
    private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
    private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
    private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;

    protected int DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO;

    private static int stringToLevel(String levelStr)
    {
        if ("trace".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_TRACE;
        }
        else if ("debug".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_DEBUG;
        }
        else if ("info".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_INFO;
        }
        else if ("warn".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_WARN;
        }
        else if ("error".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_ERROR;
        }
        return LOG_LEVEL_INFO;
    }

    public JPOSLogger(String name)
    {
        this.log = Log.getLog("Q2", "slf4j::" + name);
    }

    protected boolean isLevelEnabled(int logLevel)
    {
        Logger logger = log.getLogger();
        Configuration cfg = logger.getConfiguration();
        String levelString = cfg.get("slf4j.level", System.getProperty("slf4j.level"));
        int currentLogLevel = levelString != null ? stringToLevel(levelString) : DEFAULT_LOG_LEVEL;
        return (logLevel >= currentLogLevel);
    }

    @Override
    public boolean isTraceEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_TRACE);
    }

    @Override
    public boolean isDebugEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_DEBUG);
    }

    @Override
    public boolean isInfoEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_INFO);
    }

    @Override<commit_msg>avoid NPE<commit_after>package org.jpos.util.slf4j;

import org.jpos.core.Configuration;
import org.jpos.core.SimpleConfiguration;
import org.jpos.util.Log;
import org.jpos.util.Logger;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

@SuppressWarnings("WeakerAccess")
public class JPOSLogger extends MarkerIgnoringBase
{
    private Log log;

    private static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
    private static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
    private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
    private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
    private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;

    protected int DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO;

    private static int stringToLevel(String levelStr)
    {
        if ("trace".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_TRACE;
        }
        else if ("debug".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_DEBUG;
        }
        else if ("info".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_INFO;
        }
        else if ("warn".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_WARN;
        }
        else if ("error".equalsIgnoreCase(levelStr))
        {
            return LOG_LEVEL_ERROR;
        }
        return LOG_LEVEL_INFO;
    }

    public JPOSLogger(String name)
    {
        this.log = Log.getLog("Q2", "slf4j::" + name);
    }

    protected boolean isLevelEnabled(int logLevel)
    {
        Logger logger = log.getLogger();
        Configuration cfg = logger.getConfiguration();
        if (cfg == null)
            cfg = new SimpleConfiguration();
        String levelString = cfg.get("slf4j.level", System.getProperty("slf4j.level"));
        int currentLogLevel = levelString != null ? stringToLevel(levelString) : DEFAULT_LOG_LEVEL;
        return (logLevel >= currentLogLevel);
    }

    @Override
    public boolean isTraceEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_TRACE);
    }

    @Override
    public boolean isDebugEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_DEBUG);
    }

    @Override
    public boolean isInfoEnabled()
    {
        return isLevelEnabled(LOG_LEVEL_INFO);
    }

    @Override
{'fraction_non_alphanumeric': 0.085381091211995, 'fraction_numerical': 0.003748438150770512, 'mean_word_length': 2.851643945469126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6341560', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1400, 'n_words': 286}