<commit_before>/*
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * 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 org.jivesoftware.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;

/**
 * Openfire makes use of a logging facade (slf4j) to manage its log output. The
 * facade is backed up by Log4j by default. This class provides utility methods.
 * <p>
 * Additionally, this class provides methods that can be used to record logging
 * statements. These methods are exact duplicates of the previous Log
 * implementation of Openfire and are kept for backwards-compatibility (the are
 * deprecated). These methods will delegate logging functionality to slf4j.
 * Instead of these methods, slf4j logging functionality should be used
 * directly.
 * 
 * @author <NAME>, <EMAIL>
 * @see <a href="http://www.slf4j.org/">http://www.slf4j.org/</a>
 */
public final class Log {

    private static final org.slf4j.Logger Logger = org.slf4j.LoggerFactory.getLogger(Log.class);
    public static final SystemProperty<Boolean> DEBUG_ENABLED = SystemProperty.Builder.ofType(Boolean.class)
        .setKey("log.debug.enabled")
        .setDefaultValue(false)
        .setDynamic(true)
        .addListener(Log::setDebugEnabled)
        .build();
    /**
     * @deprecated in favour of {@link #DEBUG_ENABLED}
     */
    @Deprecated
    public static final String LOG_DEBUG_ENABLED = DEBUG_ENABLED.getKey();
    public static final SystemProperty<Boolean> TRACE_ENABLED = SystemProperty.Builder.ofType(Boolean.class)
        .setKey("log.trace.enabled")
        .setDefaultValue(false)
        .setDynamic(true)
        .addListener(Log::setTraceEnabled)
        .build();
    /**
     * @deprecated in favour of {@link #TRACE_ENABLED}
     */
    @Deprecated
    public static final String LOG_TRACE_ENABLED = TRACE_ENABLED.getKey();
    private static boolean debugEnabled = false;
    private static boolean traceEnabled = false;

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isErrorEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isErrorEnabled() {
        return Logger.isErrorEnabled();
    }

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isDebugEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isDebugEnabled() {
        return Logger.isDebugEnabled();
    }

    public static void setDebugEnabled(final boolean enabled) {
        debugEnabled = enabled;
        setLogLevel();
    }

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isTraceEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isTraceEnabled() {
        return Logger.isTraceEnabled();
    }
    
    public static void setTraceEnabled(final boolean enabled) {
        traceEnabled = enabled;
        setLogLevel();<commit_msg>OF-2282: Only re-configure logging when settings differ from default<commit_after>/*
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * 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 org.jivesoftware.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;

/**
 * Openfire makes use of a logging facade (slf4j) to manage its log output. The
 * facade is backed up by Log4j by default. This class provides utility methods.
 * <p>
 * Additionally, this class provides methods that can be used to record logging
 * statements. These methods are exact duplicates of the previous Log
 * implementation of Openfire and are kept for backwards-compatibility (the are
 * deprecated). These methods will delegate logging functionality to slf4j.
 * Instead of these methods, slf4j logging functionality should be used
 * directly.
 * 
 * @author <NAME>, <EMAIL>
 * @see <a href="http://www.slf4j.org/">http://www.slf4j.org/</a>
 */
public final class Log {

    private static final org.slf4j.Logger Logger = org.slf4j.LoggerFactory.getLogger(Log.class);
    public static final SystemProperty<Boolean> DEBUG_ENABLED = SystemProperty.Builder.ofType(Boolean.class)
        .setKey("log.debug.enabled")
        .setDefaultValue(false)
        .setDynamic(true)
        .addListener(Log::setDebugEnabled)
        .build();
    /**
     * @deprecated in favour of {@link #DEBUG_ENABLED}
     */
    @Deprecated
    public static final String LOG_DEBUG_ENABLED = DEBUG_ENABLED.getKey();
    public static final SystemProperty<Boolean> TRACE_ENABLED = SystemProperty.Builder.ofType(Boolean.class)
        .setKey("log.trace.enabled")
        .setDefaultValue(false)
        .setDynamic(true)
        .addListener(Log::setTraceEnabled)
        .build();
    /**
     * @deprecated in favour of {@link #TRACE_ENABLED}
     */
    @Deprecated
    public static final String LOG_TRACE_ENABLED = TRACE_ENABLED.getKey();
    private static boolean debugEnabled = false;
    private static boolean traceEnabled = false;

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isErrorEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isErrorEnabled() {
        return Logger.isErrorEnabled();
    }

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isDebugEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isDebugEnabled() {
        return Logger.isDebugEnabled();
    }

    public static void setDebugEnabled(final boolean enabled) {
        if (enabled != debugEnabled) {
            debugEnabled = enabled;
            setLogLevel();
        }
    }

    /**
     * @deprecated replaced by {@link org.slf4j.Logger#isTraceEnabled()}.
     *             Functionality of this method is delegated there.
     * @return {@code true} if logging is enabled, otherwise {@code false}
     */
    @Deprecated
    public static boolean isTraceEnabled() {
        return Logger.isTraceEnabled();
    }
    
    public static void setTraceEnabled(final boolean enabled) {
        if (enabled != traceEnabled) {
            traceEnabled = enabled;
            setLogLevel();
        }
{'fraction_non_alphanumeric': 0.09552628456152842, 'fraction_numerical': 0.006882639136110123, 'mean_word_length': 3.1867858917039245, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '5709500', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2296, 'n_words': 757}