org.apache.log4j.helpers.LogLog Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.log4j.helpers;
import org.apache.logging.log4j.status.StatusLogger;
/**
* Logs statements from within Log4j.
*
*
* Log4j components cannot make Log4j logging calls. However, it is sometimes useful for the user to learn about what
* Log4j is doing. You can enable Log4j internal logging by defining the log4j.configDebug variable.
*
*
* All Log4j internal debug calls go to System.out
where as internal error messages are sent to
* System.err
. All internal messages are prepended with the string "log4j: ".
*
*
* @since 0.8.2
*/
public class LogLog {
private static final StatusLogger LOGGER = StatusLogger.getLogger();
/**
* Makes Log4j print log4j-internal debug statements to System.out
.
*
*
* The value of this string is {@value #DEBUG_KEY}
*
*
* Note that the search for all option names is case sensitive.
*
*/
public static final String DEBUG_KEY = "log4j.debug";
/**
* Makes Log4j components print log4j-internal debug statements to System.out
.
*
*
* The value of this string is {@value #CONFIG_DEBUG_KEY}.
*
*
* Note that the search for all option names is case sensitive.
*
*
* @deprecated Use {@link #DEBUG_KEY} instead.
*/
@Deprecated
public static final String CONFIG_DEBUG_KEY = "log4j.configDebug";
/**
* Debug enabled Enable or disable.
*/
protected static boolean debugEnabled = false;
/**
* In quietMode not even errors generate any output.
*/
private static boolean quietMode = false;
static {
String key = OptionConverter.getSystemProperty(DEBUG_KEY, null);
if (key == null) {
key = OptionConverter.getSystemProperty(CONFIG_DEBUG_KEY, null);
}
if (key != null) {
debugEnabled = OptionConverter.toBoolean(key, true);
}
}
/**
* Logs Log4j internal debug statements.
*
* @param message the message object to log.
*/
public static void debug(final String message) {
if (debugEnabled && !quietMode) {
LOGGER.debug(message);
}
}
/**
* Logs Log4j internal debug statements.
*
* @param message the message object to log.
* @param throwable the {@code Throwable} to log, including its stack trace.
*/
public static void debug(final String message, final Throwable throwable) {
if (debugEnabled && !quietMode) {
LOGGER.debug(message, throwable);
}
}
/**
* Logs Log4j internal error statements.
*
* @param message the message object to log.
*/
public static void error(final String message) {
if (!quietMode) {
LOGGER.error(message);
}
}
/**
* Logs Log4j internal error statements.
*
* @param message the message object to log.
* @param throwable the {@code Throwable} to log, including its stack trace.
*/
public static void error(final String message, final Throwable throwable) {
if (!quietMode) {
LOGGER.error(message, throwable);
}
}
/**
* Enables and disables Log4j internal logging.
*
* @param enabled Enable or disable.
*/
static public void setInternalDebugging(final boolean enabled) {
debugEnabled = enabled;
}
/**
* In quite mode no LogLog generates strictly no output, not even for errors.
*
* @param quietMode A true for not
*/
public static void setQuietMode(final boolean quietMode) {
LogLog.quietMode = quietMode;
}
/**
* Logs Log4j internal warning statements.
*
* @param message the message object to log.
*/
public static void warn(final String message) {
if (!quietMode) {
LOGGER.warn(message);
}
}
/**
* Logs Log4j internal warnings.
*
* @param message the message object to log.
* @param throwable the {@code Throwable} to log, including its stack trace.
*/
public static void warn(final String message, final Throwable throwable) {
if (!quietMode) {
LOGGER.warn(message, throwable);
}
}
}