001: /**
002: * $Id: PSConsoleLogManager.java,v 1.2 2005/07/15 05:39:37 hc109819 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console;
014:
015: import java.net.URL;
016: import java.io.File;
017: import java.io.InputStream;
018: import java.io.IOException;
019: import java.util.logging.Logger;
020: import java.util.Properties;
021:
022: import javax.servlet.ServletContext;
023:
024: import com.sun.portal.log.common.PortalLogManager;
025: import com.sun.portal.log.common.PortalLogger;
026:
027: import com.sun.portal.admin.console.common.PSServletContextListener;
028:
029: public class PSConsoleLogManager {
030: public static final String PSCONSOLE_LOGCONFIG_STANDALONE_DEPLOY = "standalone.deploy";
031: public static final String PSCONSOLE_LOGCONFIG_FILE = "/WEB-INF/classes/pslogconfig.properties";
032: public static final String PS_LOGGER_SYSPROP = "com.sun.portal.log.config.file";
033: private static Logger logger = null;
034: private static boolean sadeploy = false;
035: private static Properties logcfgProps = null;
036:
037: public PSConsoleLogManager() {
038: }
039:
040: public static boolean isStandAloneDeploy() {
041: return sadeploy;
042: }
043:
044: private static void initLogConfig() {
045: ServletContext sc = PSServletContextListener
046: .getServletContext();
047: if (sc != null) {
048: InputStream is = sc
049: .getResourceAsStream(PSCONSOLE_LOGCONFIG_FILE);
050: if (is != null) {
051: logcfgProps = new Properties();
052: try {
053: logcfgProps.load(is);
054: String val = logcfgProps
055: .getProperty(PSCONSOLE_LOGCONFIG_STANDALONE_DEPLOY);
056: sadeploy = Boolean.valueOf(val).booleanValue();
057: } catch (IOException ioe) {
058: // TODO: log error, but where?
059: } catch (IllegalArgumentException iae) {
060: // TODO: log error, but where?
061: }
062: }
063: }
064: }
065:
066: public static synchronized void init() {
067: initLogConfig();
068: if (!isStandAloneDeploy()) {
069: try {
070: // init the ps logger when the log config file sys properties is set
071: String val = System.getProperty(PS_LOGGER_SYSPROP);
072: if (val != null) {
073: logger = PortalLogger
074: .getLogger(PSConsoleLogManager.class);
075: } else {
076: sadeploy = true;
077: reset();
078: }
079: } catch (Exception e) {
080: sadeploy = true;
081: reset();
082: }
083: }
084: }
085:
086: public static void reset() {
087: logger = null;
088: }
089:
090: public static Logger getLogger() {
091: if ((logger == null) && (!isStandAloneDeploy())) {
092: init();
093: }
094: return logger;
095: }
096:
097: public static ServletContext getContextLogger() {
098: return PSServletContextListener.getServletContext();
099: }
100:
101: }
|