01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.util.logging;
20:
21: import org.apache.log4j.AppenderSkeleton;
22: import org.apache.log4j.Level;
23: import org.apache.log4j.spi.LoggingEvent;
24:
25: /**
26: * Special log4j appender, that passes the logging event to the
27: * {@link de.schlund.pfixxml.util.logging.ProxyLogUtil} class.
28: * This appender should only if the webapplication's instance
29: * of log4j cannot log itself (e.g. because the application is in
30: * a packed WAR file}.
31: *
32: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
33: */
34: public class ProxyLogAppender extends AppenderSkeleton {
35: private ProxyLogUtil util = ProxyLogUtil.getInstance();
36:
37: protected void append(LoggingEvent event) {
38: String name = event.getLoggerName();
39: Level lvl = event.getLevel();
40: Throwable ex = null;
41: if (event.getThrowableInformation() != null) {
42: ex = event.getThrowableInformation().getThrowable();
43: }
44: Object msg = event.getMessage();
45:
46: if (lvl.isGreaterOrEqual(Level.FATAL)) {
47: if (ex == null)
48: util.doLogLog4j(name, ProxyLogUtil.Level.FATAL, msg);
49: else
50: util
51: .doLogLog4j(name, ProxyLogUtil.Level.FATAL,
52: msg, ex);
53: } else if (lvl.isGreaterOrEqual(Level.ERROR)) {
54: if (ex == null)
55: util.doLogLog4j(name, ProxyLogUtil.Level.ERROR, msg);
56: else
57: util
58: .doLogLog4j(name, ProxyLogUtil.Level.ERROR,
59: msg, ex);
60: } else if (lvl.isGreaterOrEqual(Level.WARN)) {
61: if (ex == null)
62: util.doLogLog4j(name, ProxyLogUtil.Level.WARN, msg);
63: else
64: util.doLogLog4j(name, ProxyLogUtil.Level.WARN, msg, ex);
65: } else if (lvl.isGreaterOrEqual(Level.INFO)) {
66: if (ex == null)
67: util.doLogLog4j(name, ProxyLogUtil.Level.INFO, msg);
68: else
69: util.doLogLog4j(name, ProxyLogUtil.Level.INFO, msg, ex);
70: } else if (lvl.isGreaterOrEqual(Level.DEBUG)) {
71: if (ex == null)
72: util.doLogLog4j(name, ProxyLogUtil.Level.DEBUG, msg);
73: else
74: util
75: .doLogLog4j(name, ProxyLogUtil.Level.DEBUG,
76: msg, ex);
77: } else {
78: if (ex == null)
79: util.doLogLog4j(name, ProxyLogUtil.Level.TRACE, msg);
80: else
81: util
82: .doLogLog4j(name, ProxyLogUtil.Level.TRACE,
83: msg, ex);
84: }
85: }
86:
87: public boolean requiresLayout() {
88: return false;
89: }
90:
91: public void close() {
92: // Intentionally left blank
93: }
94:
95: }
|