001: /*
002: * OutputLogger.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.executequery.util;
023:
024: import java.io.IOException;
025:
026: import org.apache.log4j.LogManager;
027: import org.apache.log4j.Logger;
028: import org.apache.log4j.PatternLayout;
029: import org.apache.log4j.RollingFileAppender;
030:
031: /* ----------------------------------------------------------
032: * CVS NOTE: Changes to the CVS repository prior to the
033: * release of version 3.0.0beta1 has meant a
034: * resetting of CVS revision numbers.
035: * ----------------------------------------------------------
036: */
037:
038: /**
039: *
040: * @author Takis Diakoumis
041: * @version $Revision: 1.5 $
042: * @date $Date: 2006/05/14 06:56:52 $
043: */
044: public class OutputLogger {
045:
046: private OutputLogger() {
047: }
048:
049: public static void initialiseLogger(String name, String layout,
050: String path, int maxBackups) throws IOException {
051:
052: if (LogManager.exists(name) != null) {
053: return;
054: }
055:
056: Logger logger = Logger.getLogger(name);
057: PatternLayout patternLayout = new PatternLayout();
058: patternLayout.setConversionPattern(layout);
059:
060: RollingFileAppender appender = new RollingFileAppender(
061: patternLayout, path, true);
062: appender.setMaxBackupIndex(maxBackups);
063: appender.setMaxFileSize("1MB");
064: logger.addAppender(appender);
065: }
066:
067: public static synchronized void append(String name, String text) {
068: Logger logger = Logger.getLogger(name);
069: if (logger != null) {
070: logger.info(text);
071: }
072: }
073:
074: public static void info(String name, String message,
075: Throwable throwable) {
076: Logger logger = Logger.getLogger(name);
077: if (logger != null) {
078: logger.info(message, throwable);
079: }
080: }
081:
082: public static void warning(String name, String message,
083: Throwable throwable) {
084: Logger logger = Logger.getLogger(name);
085: if (logger != null) {
086: logger.warn(message, throwable);
087: }
088: }
089:
090: public static void debug(String name, String message) {
091: Logger logger = Logger.getLogger(name);
092: if (logger != null) {
093: logger.debug(message);
094: }
095: }
096:
097: public static void debug(String name, String message,
098: Throwable throwable) {
099: Logger logger = Logger.getLogger(name);
100: if (logger != null) {
101: logger.debug(message, throwable);
102: }
103: }
104:
105: public static void error(String name, String message,
106: Throwable throwable) {
107: Logger logger = Logger.getLogger(name);
108: if (logger != null) {
109: logger.error(message, throwable);
110: }
111: }
112:
113: public static void info(String name, String message) {
114: Logger logger = Logger.getLogger(name);
115: if (logger != null) {
116: logger.info(message);
117: }
118: }
119:
120: public static void warning(String name, String message) {
121: Logger logger = Logger.getLogger(name);
122: if (logger != null) {
123: logger.warn(message);
124: }
125: }
126:
127: public static void error(String name, String message) {
128: Logger logger = Logger.getLogger(name);
129: if (logger != null) {
130: logger.error(message);
131: }
132: }
133:
134: }
|