001: /*
002: * This file is part of "SnipSnap Radeox Rendering Engine".
003: *
004: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
005: * All Rights Reserved.
006: *
007: * Please visit http://radeox.org/ for updates and contact.
008: *
009: * --LICENSE NOTICE--
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * --LICENSE NOTICE--
022: */
023:
024: package org.radeox.util.logging;
025:
026: import java.text.DateFormat;
027: import java.text.SimpleDateFormat;
028: import java.util.Date;
029:
030: /**
031: * Logger for logging events. Logger uses al LoggerImplementation for logging
032: * concrete logging, e.g. SystemOutLogger
033: *
034: * @author stephan
035: * @version $Id: Logger.java 7756 2006-04-13 12:25:49Z ian@caret.cam.ac.uk $
036: */
037:
038: public class Logger {
039: // private static LogHandler handler = new ApplicationLogger();
040: private static LogHandler handler = new SystemErrLogger();
041:
042: public final static boolean PRINT_STACKTRACE = true;
043:
044: public final static DateFormat format = new SimpleDateFormat(
045: "hh:mm:ss.SSS");
046:
047: public final static int ALL = -1;
048:
049: public final static int NONE = 4;
050:
051: public final static int PERF = 0;
052:
053: public final static int DEBUG = 1;
054:
055: public final static int WARN = 2;
056:
057: public final static int FATAL = 3;
058:
059: public final static int LEVEL = ALL;
060:
061: public final static String[] levels = { "PERF ", "DEBUG ",
062: "WARN ", "FATAL " };
063:
064: public static void log(String output) {
065: if (LEVEL <= DEBUG)
066: log(Logger.DEBUG, output);
067: }
068:
069: public static void perf(String output) {
070: if (LEVEL <= PERF)
071: log(Logger.PERF, output);
072: }
073:
074: public static void debug(String output) {
075: if (LEVEL <= DEBUG)
076: log(Logger.DEBUG, output);
077: }
078:
079: public static void warn(String output) {
080: if (LEVEL <= WARN)
081: log(Logger.WARN, output);
082: }
083:
084: public static void warn(String output, Throwable e) {
085: if (LEVEL <= WARN)
086: log(Logger.WARN, output, e);
087: }
088:
089: public static void fatal(String output) {
090: if (LEVEL <= FATAL)
091: log(Logger.WARN, output);
092: }
093:
094: public static void fatal(String output, Exception e) {
095: if (LEVEL <= FATAL)
096: log(Logger.WARN, output, e);
097: }
098:
099: public static void log(String output, Exception e) {
100: if (LEVEL <= DEBUG)
101: log(Logger.DEBUG, output, e);
102: }
103:
104: public static void log(int level, String output) {
105: handler.log(format.format(new Date()) + " " + levels[level]
106: + " - " + output);
107: }
108:
109: public static void log(int level, String output, Throwable e) {
110: handler.log(format.format(new Date()) + " " + levels[level]
111: + " - " + output + ": " + e.getMessage(), e);
112: }
113:
114: public static void setHandler(LogHandler handler) {
115: Logger.handler = handler;
116: }
117: }
|