All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enhydra.xml.xmlc.servlet.ServletXMLCLogger Maven / Gradle / Ivy

The newest version!
/*
 * Enhydra Java Application Server Project
 * 
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site ( http://www.enhydra.org/ ).
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
 * the License for the specific terms governing rights and limitations
 * under the License.
 * 
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * $Id: ServletXMLCLogger.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
 */

package org.enhydra.xml.xmlc.servlet;

import java.io.PrintWriter;

import javax.servlet.ServletContext;

import org.enhydra.xml.xmlc.XMLCLogger;

/**
 * XMLC logger interface to the Servlet logging API.
 */
class ServletXMLCLogger implements XMLCLogger {
    /**
     * ServletContext this logger is associated with.
     */
    private ServletContext fServletContext;

    /**
     * Writer for XMLC informative logging.
     */
    private PrintWriter fInfoWriter;

    /**
     * Writer for XMLC debug logging.
     */
    private PrintWriter fDebugWriter;

    /**
     * Writer for XMLC error logging.
     */
    private PrintWriter fErrorWriter;

    /**
     * Constructor.
     */
    public ServletXMLCLogger(ServletContext servletContext,
                             boolean enableInfoLogging,
                             boolean enableDebugLogging) {
        fServletContext = servletContext;

        // Writer fields also serve as an indication if logging is enabled.
        PrintWriter writer = new PrintWriter(new ServletLogWriter(fServletContext),
                                             true);
        if (enableInfoLogging) {
            fInfoWriter = writer;
        }
        if (enableDebugLogging) {
            fDebugWriter = writer;
        }
        fErrorWriter = writer;
    }

    /**
     * Determine if info logging is enabled.
     */
    public boolean infoEnabled() {
        return (fInfoWriter != null);
    }

    /**
     * Get the info logging writer.
     */
    public PrintWriter getInfoWriter() {
        return fInfoWriter;
    }

    /**
     * Log an info message.
     */
    public void logInfo(String msg) {
        if (fInfoWriter != null) {
            fServletContext.log(msg);
        }
    }

    /**
     * Log an info message with exception.
     */
    public void logInfo(String msg,
                        Throwable except) {
        if (fInfoWriter != null) {
            fServletContext.log(msg, except);
        }
    }

    /**
     * Determine if error logging is enabled.
     */
    public boolean errorEnabled() {
        return (fErrorWriter != null);
    }

    /**
     * Get the error logging writer.
     */
    public PrintWriter getErrorWriter() {
        return fErrorWriter;
    }

    /**
     * Log an error message.
     */
    public void logError(String msg) {
        if (fErrorWriter != null) {
            fServletContext.log(msg);
        }
    }

    /**
     * Log an error message with exception.
     */
    public void logError(String msg,
                         Throwable except) {
        if (fErrorWriter != null) {
            fServletContext.log(msg, except);
        }
    }

    /**
     * Determine if debug logging is enabled.
     */
    public boolean debugEnabled() {
        return (fDebugWriter != null);
    }

    /**
     * Get the debug logging writer.
     */
    public PrintWriter getDebugWriter() {
        return fDebugWriter;
    }

    /**
     * Log a debug message.
     */
    public void logDebug(String msg) {
        if (fDebugWriter != null) {
            fServletContext.log(msg);
        }
    }

    /**
     * Log a debug message with exception.
     */
    public void logDebug(String msg,
                         Throwable except) {
        if (fDebugWriter != null) {
            fServletContext.log(msg, except);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy