001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package org.huihoo.jfox.logging;
009:
010: import org.apache.log4j.Level;
011:
012: /**
013: *
014: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
015: */
016:
017: public class Logger {
018: private org.apache.log4j.Logger logger;
019:
020: static {
021: _init();
022: }
023:
024: /**
025: * set rootLogger
026: */
027: private static void _init() {
028: LogManager.class.getName();
029: }
030:
031: public static Logger getLogger(String name) {
032: return new Logger(name);
033: }
034:
035: private Logger(String name) {
036: logger = org.apache.log4j.Logger.getLogger(name);
037: }
038:
039: /**
040: * <p> Log a message with debug log level. </p>
041: *
042: * @param message log this message
043: */
044: public void debug(Object message) {
045: logger.log(Level.DEBUG, message);
046: }
047:
048: /**
049: * <p> Log an error with debug log level. </p>
050: *
051: * @param message log this message
052: * @param t log this cause
053: */
054: public void debug(Object message, Throwable t) {
055: logger.log(Level.DEBUG, message, t);
056: }
057:
058: /**
059: * <p> Log a message with info log level. </p>
060: *
061: * @param message log this message
062: */
063: public void info(Object message) {
064: logger.log(Level.INFO, message);
065: }
066:
067: /**
068: * <p> Log an error with info log level. </p>
069: *
070: * @param message log this message
071: * @param t log this cause
072: */
073: public void info(Object message, Throwable t) {
074: logger.log(Level.INFO, message, t);
075: }
076:
077: /**
078: * <p> Log a message with warn log level. </p>
079: *
080: * @param message log this message
081: */
082: public void warn(Object message) {
083: logger.log(Level.WARN, message);
084: }
085:
086: /**
087: * <p> Log an error with warn log level. </p>
088: *
089: * @param message log this message
090: * @param t log this cause
091: */
092: public void warn(Object message, Throwable t) {
093: logger.log(Level.WARN, message, t);
094: }
095:
096: /**
097: * <p> Log a message with error log level. </p>
098: *
099: * @param message log this message
100: */
101: public void error(Object message) {
102: logger.log(Level.ERROR, message);
103: }
104:
105: /**
106: * <p> Log an error with error log level. </p>
107: *
108: * @param message log this message
109: * @param t log this cause
110: */
111: public void error(Object message, Throwable t) {
112: logger.log(Level.ERROR, message, t);
113: }
114:
115: /**
116: * <p> Log a message with fatal log level. </p>
117: *
118: * @param message log this message
119: */
120: public void fatal(Object message) {
121: logger.log(Level.FATAL, message);
122: }
123:
124: /**
125: * <p> Log an error with fatal log level. </p>
126: *
127: * @param message log this message
128: * @param t log this cause
129: */
130: public void fatal(Object message, Throwable t) {
131: logger.log(Level.FATAL, message, t);
132: }
133:
134: public static void main(String[] args) {
135: Logger logger = Logger.getLogger("test");
136: logger.info("test message");
137:
138: }
139:
140: }
|