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

📄 logmanager.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
字号:
/*
 * LogManager.java
 *
 * Created on 2003/07/10, 18:00
 */

package jp.co.intra_mart.framework.system.log;

import java.util.ResourceBundle;

import jp.co.intra_mart.framework.system.property.PropertyManager;

import java.util.MissingResourceException;

import jp.co.intra_mart.framework.system.property.PropertyHandlerException;
import jp.co.intra_mart.framework.system.property.PropertyManagerException;

/**
 * 儘僌儅僱乕僕儍偱偡丅
 *
 * @author INTRAMART
 * @since 4.2
 */
public class LogManager {

    /**
     * 儘僌僼儗乕儉儚乕僋偺儘僌偺僾儗僼傿僢僋僗
     */
    static String LOG_HEAD = "[J2EE][Log]";

    /**
     * 儘僌僾儘僷僥傿僴儞僪儔偺僉乕
     */
    public static final String LOG_PROPERTY_HANDLER_KEY = "log";

    /**
     * 儘僌儅僱乕僕儍庢摼僼儔僌
     */
    private static Boolean managerFlag = new Boolean(false);

    /**
     * 儘僌儅僱乕僕儍
     */
    private static LogManager manager = null;

    /**
     * 儘僌僾儘僷僥傿僴儞僪儔
     */
    private LogPropertyHandler logPropertyHandler = null;

    /**
     * 儘僌僄乕僕僃儞僩
     */
    private LogAgent agent = null;

    /**
     * 儘僌儅僱乕僕儍傪庢摼偟傑偡丅
     *
     * @return 儘僌儅僱乕僕儍
     */
    public static LogManager getLogManager() {

        if (!managerFlag.booleanValue()) {
            synchronized (managerFlag) {
                if (!managerFlag.booleanValue()) {
                    manager = new LogManager();
                    managerFlag = new Boolean(true);
                    String message = null;
                }

                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                            .getString("LogManager.SuccessedToCreateManager");
                } catch (MissingResourceException ex) {
                }
                manager.getLogAgent().sendMessage(
                    LogManager.class.getName(),
                    LogConstant.LEVEL_INFO,
                    LOG_HEAD + message);
            }
        }

        return manager;
    }

    /**
     * LogManager傪惗惉偡傞僐儞僗僩儔僋僞偱偡丅
     * 偙偺僐儞僗僩儔僋僞偼柧帵揑偵屇傃弌偡偙偲偼偱偒傑偣傫丅
     */
    private LogManager() {
        PropertyManager propertyManager = null;
        Object agentObject = null;
        String className = null;
        LogAgent tempAgent = null;

        // 僾儘僷僥傿儅僱乕僕儍偺庢摼
        try {
            propertyManager = PropertyManager.getPropertyManager();
        } catch (PropertyManagerException e) {
            // 僾儘僷僥傿儅僱乕僕儍偺庢摼偵幐攕偟偨応崌丄
            // 僨僼僅儖僩偺儘僌僄乕僕僃儞僩傪惗惉偡傞丅
            this.agent = new DefaultLogAgent();
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                        .getString("LogManager.FailedToGetPropertyManager");
            } catch (MissingResourceException ex) {
            }
            this.agent.sendMessage(
                LogManager.class.getName(),
                LogConstant.LEVEL_ERROR,
                message + " : " + LOG_PROPERTY_HANDLER_KEY,
                e);
            return;
        }

        // 儘僌僾儘僷僥傿僴儞僪儔偺庢摼
        try {
            this.logPropertyHandler =
                (LogPropertyHandler)propertyManager.getPropertyHandler(
                    LOG_PROPERTY_HANDLER_KEY);
        } catch (PropertyHandlerException e) {
            // 儘僌僾儘僷僥傿僴儞僪儔偺庢摼偵幐攕偟偨応崌丄
            // 僨僼僅儖僩偺儘僌僄乕僕僃儞僩傪惗惉偡傞丅
            this.agent = new DefaultLogAgent();
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                        .getString("LogManager.FailedToGetLogPropertyHandler");
            } catch (MissingResourceException ex) {
            }
            this.agent.sendMessage(
                LogManager.class.getName(),
                LogConstant.LEVEL_WARNNING,
                message + " : " + LOG_PROPERTY_HANDLER_KEY);
            return;
        }

        // 儘僌僄乕僕僃儞僩偺僋儔僗柤偺庢摼
        try {
            className = this.logPropertyHandler.getLogAgentName();
        } catch (LogPropertyException e) {
            // 儘僌僄乕僕僃儞僩偺僋儔僗柤庢摼偵幐攕偟偨応崌丄
            // 僨僼僅儖僩偺儘僌僄乕僕僃儞僩傪惗惉偡傞丅
            this.agent = new DefaultLogAgent();
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                        .getString("LogManager.FailedToGetAgentName");
            } catch (MissingResourceException ex) {
            }
            this.agent.sendMessage(
                LogManager.class.getName(),
                LogConstant.LEVEL_ERROR,
                message + " : " + LOG_PROPERTY_HANDLER_KEY,
                e);
            return;
        }

        // 儘僌僄乕僕僃儞僩偺惗惉
        if (className != null) {
            try {
                agentObject = Class.forName(className).newInstance();
            } catch (Exception e) {
                // 儘僌僄乕僕僃儞僩偺惗惉偵幐攕偟偨応崌丄
                // 僨僼僅儖僩偺儘僌僄乕僕僃儞僩傪惗惉偡傞丅
                this.agent = new DefaultLogAgent();
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                            .getString("LogManager.FailedToCreateAgent");
                } catch (MissingResourceException ex) {
                }
                this.agent.sendMessage(
                    LogManager.class.getName(),
                    LogConstant.LEVEL_ERROR,
                    message + " : " + LOG_PROPERTY_HANDLER_KEY,
                    e);
                return;
            }
            if (agentObject instanceof LogAgent) {
                tempAgent = (LogAgent)agentObject;
            } else {
                // 儘僌僄乕僕僃儞僩偺惗惉偵幐攕偟偨応崌丄
                // 僨僼僅儖僩偺儘僌僄乕僕僃儞僩傪惗惉偡傞丅
                this.agent = new DefaultLogAgent();
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                            .getString("LogManager.AgentImplemented");
                } catch (MissingResourceException ex) {
                }
                this.agent.sendMessage(
                    LogManager.class.getName(),
                    LogConstant.LEVEL_ERROR,
                    message
                        + " ("
                        + agentObject.getClass().getName()
                        + ") : "
                        + LOG_PROPERTY_HANDLER_KEY);
                return;
            }
        }

        // 儘僌僄乕僕僃儞僩偺弶婜壔
        LogAgentParam[] params = null;
        try {
            params = this.logPropertyHandler.getLogAgentParams();
        } catch (LogPropertyException e) {
            // 弶婜壔僷儔儊乕僞偺庢摼偵幐攕偟偨応崌丄
            // 僷儔儊乕僞偼側偟
            this.agent = tempAgent;
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.system.log.i18n")
                        .getString("LogManager.FailedToGetAgentParameters");
            } catch (MissingResourceException ex) {
            }
            this.agent.sendMessage(
                LogManager.class.getName(),
                LogConstant.LEVEL_ERROR,
                message + " : " + LOG_PROPERTY_HANDLER_KEY,
                e);
            return;
        }
        tempAgent.init(params);
        this.agent = tempAgent;
    }

    /**
     * 儘僌僾儘僷僥傿僴儞僪儔傪庢摼偟傑偡丅
     *
     * @return 儘僌僾儘僷僥傿僴儞僪儔
     */
    public LogPropertyHandler getLogPropertyHandler() {
        return this.logPropertyHandler;
    }

    /**
     * 儘僌僄乕僕僃儞僩傪庢摼偟傑偡丅
     *
     * @return 儘僌僄乕僕僃儞僩
     */
    public LogAgent getLogAgent() {
        return this.agent;
    }
}

⌨️ 快捷键说明

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