001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.webadapter;
039:
040: /** <p>Class providing centralized logging services. The logger defines
041: * five message types, and provides methods to create messages of those
042: * types. These types are:</p>
043: *
044: * <ul>
045: * <li> <code>info</code> - Useful information generated during normal
046: * operation of the application
047: * <li> <code>warning</code> - An error situation has occurred, but the
048: * operation was able to finish succesfully
049: * <li> <code>error</code> - An error situation which prevented the
050: * operation from finishing succesfully
051: * <li> <code>debug</code> - Internal information from the application meant
052: * for developers
053: * <li> <code>exception</code> - A Java exception reported using the logger.
054: * Includes the exception stack trace and a possible free-form message
055: * </ul>
056: *
057: * <p>Currently the class offers logging only to the standard output</p>
058: *
059: * @author IT Mill Ltd.
060: * @version 3.1.1
061: * @since 3.0
062: */
063: public class Log {
064:
065: private static String logFilename;
066: private static boolean useStdOut = true;
067:
068: private static String LOG_MSG_INFO = "[INFO]";
069: private static String LOG_MSG_ERROR = "[ERROR]";
070: private static String LOG_MSG_WARN = "[WARNING]";
071: private static String LOG_MSG_DEBUG = "[DEBUG]";
072: private static String LOG_MSG_EXCEPT = "[EXCEPTION]";
073:
074: /** Logs a <code>warning</code> message.
075: *
076: * @param message Message <code>String</code> to be logged.
077: */
078: protected static synchronized void warn(java.lang.String message) {
079: if (Log.useStdOut)
080: System.out.println(LOG_MSG_WARN + " " + message);
081: }
082:
083: /** Logs a <code>debug</code> message.
084: *
085: * @param message Message <code>String</code> to be logged.
086: */
087: protected static synchronized void debug(java.lang.String message) {
088: if (Log.useStdOut)
089: System.out.println(LOG_MSG_DEBUG + " " + message);
090: }
091:
092: /** Logs an <code>info</code> message.
093: *
094: * @param message Message <code>String</code> to be logged.
095: */
096: protected static synchronized void info(java.lang.String message) {
097: if (Log.useStdOut)
098: System.out.println(LOG_MSG_INFO + " " + message);
099: }
100:
101: /** Logs a Java exception and an accompanying error message.
102: *
103: * @param message Message <code>String</code> to be logged.
104: * @param e Exception to be logged.
105: */
106: protected static synchronized void except(java.lang.String message,
107: Exception e) {
108: if (Log.useStdOut) {
109: System.out.println(LOG_MSG_EXCEPT + " " + message);
110: e.printStackTrace();
111: }
112: }
113:
114: /** Logs an <code>error</code> message.
115: *
116: * @param message Message <code>String</code> to be logged.
117: */
118: protected static synchronized void error(java.lang.String message) {
119: if (Log.useStdOut)
120: System.out.println(LOG_MSG_ERROR + " " + message);
121: }
122: }
|