⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logger.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE file. */package org.jivesoftware.util.log;/** * The object interacted with by client objects to perform logging. * * @author <a href="mailto:peter@apache.org">Peter Donald</a> */public class Logger {    ///Separator character use to separate different categories    public final static char CATEGORY_SEPARATOR = '.';    ///The ErrorHandler associated with Logger    private final ErrorHandler m_errorHandler;    ///Logger to inherit logtargets and priorities from    private final Logger m_parent;    ///the fully qualified name of category    private final String m_category;    ///The list of child loggers associated with this logger    private Logger[] m_children;    ///The log-targets this logger writes to    private LogTarget[] m_logTargets;    ///Indicate that logTargets were set with setLogTargets() rather than inherited    private boolean m_logTargetsForceSet;    ///The priority threshold associated with logger    private Priority m_priority;    ///Indicate that priority was set with setPriority() rather than inherited    private boolean m_priorityForceSet;    /**     * True means LogEvents will be sent to parents LogTargets     * aswell as the ones set for this Logger.     */    private boolean m_additivity;    /**     * Protected constructor for use inside the logging toolkit.     * You should not be using this constructor directly.     *     * @param errorHandler the ErrorHandler logger uses to log errors     * @param category     the fully qualified name of category     * @param logTargets   the LogTargets associated with logger     * @param parent       the parent logger (used for inheriting from)     */    Logger(final ErrorHandler errorHandler,           final String category,           final LogTarget[] logTargets,           final Logger parent) {        m_errorHandler = errorHandler;        m_category = category;        m_logTargets = logTargets;        m_parent = parent;        if (null == m_logTargets) {            unsetLogTargets();        }        unsetPriority();    }    /**     * Determine if messages of priority DEBUG will be logged.     *     * @return true if DEBUG messages will be logged     */    public final boolean isDebugEnabled() {        return m_priority.isLowerOrEqual(Priority.DEBUG);    }    /**     * Log a debug priority event.     *     * @param message   the message     * @param throwable the throwable     */    public final void debug(final String message, final Throwable throwable) {        if (isDebugEnabled()) {            output(Priority.DEBUG, message, throwable);        }    }    /**     * Log a debug priority event.     *     * @param message the message     */    public final void debug(final String message) {        if (isDebugEnabled()) {            output(Priority.DEBUG, message, null);        }    }    /**     * Determine if messages of priority INFO will be logged.     *     * @return true if INFO messages will be logged     */    public final boolean isInfoEnabled() {        return m_priority.isLowerOrEqual(Priority.INFO);    }    /**     * Log a info priority event.     *     * @param message the message     */    public final void info(final String message, final Throwable throwable) {        if (isInfoEnabled()) {            output(Priority.INFO, message, throwable);        }    }    /**     * Log a info priority event.     *     * @param message the message     */    public final void info(final String message) {        if (isInfoEnabled()) {            output(Priority.INFO, message, null);        }    }    /**     * Determine if messages of priority WARN will be logged.     *     * @return true if WARN messages will be logged     */    public final boolean isWarnEnabled() {        return m_priority.isLowerOrEqual(Priority.WARN);    }    /**     * Log a warn priority event.     *     * @param message   the message     * @param throwable the throwable     */    public final void warn(final String message, final Throwable throwable) {        if (isWarnEnabled()) {            output(Priority.WARN, message, throwable);        }    }    /**     * Log a warn priority event.     *     * @param message the message     */    public final void warn(final String message) {        if (isWarnEnabled()) {            output(Priority.WARN, message, null);        }    }    /**     * Determine if messages of priority ERROR will be logged.     *     * @return true if ERROR messages will be logged     */    public final boolean isErrorEnabled() {        return m_priority.isLowerOrEqual(Priority.ERROR);    }    /**     * Log a error priority event.     *     * @param message   the message     * @param throwable the throwable     */    public final void error(final String message, final Throwable throwable) {        if (isErrorEnabled()) {            output(Priority.ERROR, message, throwable);        }    }    /**     * Log a error priority event.     *     * @param message the message     */    public final void error(final String message) {        if (isErrorEnabled()) {            output(Priority.ERROR, message, null);        }    }    /**     * Determine if messages of priority FATAL_ERROR will be logged.     *     * @return true if FATAL_ERROR messages will be logged     */    public final boolean isFatalErrorEnabled() {        return m_priority.isLowerOrEqual(Priority.FATAL_ERROR);    }    /**     * Log a fatalError priority event.     *     * @param message   the message     * @param throwable the throwable     */    public final void fatalError(final String message, final Throwable throwable) {        if (isFatalErrorEnabled()) {            output(Priority.FATAL_ERROR, message, throwable);        }    }    /**     * Log a fatalError priority event.     *     * @param message the message     */    public final void fatalError(final String message) {        if (isFatalErrorEnabled()) {            output(Priority.FATAL_ERROR, message, null);        }    }    /**     * Make this logger additive, which means send all log events to parent     * loggers LogTargets regardless of whether or not the     * LogTargets have been overidden.     * <p/>     * This is derived from Log4js notion of Additivity.     *     * @param additivity true to make logger additive, false otherwise     */    public final void setAdditivity(final boolean additivity) {        m_additivity = additivity;    }    /**     * Determine if messages of priority will be logged.     *     * @return true if messages will be logged     */    public final boolean isPriorityEnabled(final Priority priority) {        return m_priority.isLowerOrEqual(priority);    }    /**     * Log a event at specific priority with a certain message and throwable.     *     * @param message   the message     * @param priority  the priority     * @param throwable the throwable     */    public final void log(final Priority priority,                          final String message,                          final Throwable throwable) {        if (m_priority.isLowerOrEqual(priority)) {            output(priority, message, throwable);        }    }    /**     * Log a event at specific priority with a certain message.     *     * @param message  the message     * @param priority the priority     */    public final void log(final Priority priority, final String message) {        log(priority, message, null);    }    /**     * Set the priority for this logger.     *     * @param priority the priority     */    public synchronized void setPriority(final Priority priority) {        m_priority = priority;        m_priorityForceSet = true;        resetChildPriorities(false);    }    /**     * Unset the priority of Logger.     * (Thus it will use it's parent's priority or DEBUG if no parent.     */    public synchronized void unsetPriority() {        unsetPriority(false);    }    /**     * Unset the priority of Logger.     * (Thus it will use it's parent's priority or DEBUG if no parent.     * If recursive is true unset priorities of all child loggers.     *     * @param recursive true to unset priority of all child loggers     */    public synchronized void unsetPriority(final boolean recursive) {        if (null != m_parent)            m_priority = m_parent.m_priority;        else            m_priority = Priority.DEBUG;        m_priorityForceSet = false;        resetChildPriorities(recursive);    }    /**     * Set the log targets for this logger.     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -