01: /**
02: * $Revision$
03: * $Date$
04: *
05: * Copyright (C) 2006-2007 Jive Software. All rights reserved.
06: *
07: * This software is published under the terms of the GNU Public License (GPL),
08: * a copy of which is included in this distribution.
09: */package org.jivesoftware.openfire.gateway.util;
10:
11: import org.apache.log4j.AppenderSkeleton;
12: import org.apache.log4j.Level;
13: import org.apache.log4j.Priority;
14: import org.apache.log4j.spi.LoggingEvent;
15: import org.jivesoftware.util.Log;
16:
17: /**
18: * This is a modified version of the standard appender that forced everything to go to the debug log.
19: * TODO: It's possible this could be done via config options but I can't tell.
20: * @author Guus der Kinderen, guus@nimbuzz.com
21: * @author Daniel Henninger
22: */
23: public class DebugOnlyLog4JToOpenfireAppender extends AppenderSkeleton {
24:
25: /*
26: * (non-Javadoc)
27: *
28: * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
29: */
30: @Override
31: protected void append(LoggingEvent event) {
32: final Level l = event.getLevel();
33: final String message = event.getMessage().toString();
34:
35: Throwable throwable = null;
36: if (event.getThrowableInformation() != null) {
37: throwable = event.getThrowableInformation().getThrowable();
38: }
39:
40: switch (l.toInt()) {
41: case Priority.OFF_INT:
42: // Logging turned off - do nothing.
43: break;
44:
45: case Priority.FATAL_INT:
46: case Priority.ERROR_INT:
47: Log.debug(message, throwable);
48: break;
49:
50: case Priority.WARN_INT:
51: Log.debug(message, throwable);
52: break;
53:
54: case Priority.INFO_INT:
55: Log.debug(message, throwable);
56: break;
57:
58: default:
59: // DEBUG and below (trace, all)
60: Log.debug(message, throwable);
61: break;
62: }
63: }
64:
65: /*
66: * (non-Javadoc)
67: *
68: * @see org.apache.log4j.AppenderSkeleton#close()
69: */
70: @Override
71: public void close() {
72: // There's nothing here to close.
73: }
74:
75: /*
76: * (non-Javadoc)
77: *
78: * @see org.apache.log4j.AppenderSkeleton#requiresLayout()
79: */
80: @Override
81: public boolean requiresLayout() {
82: // we're doing this quick and dirty.
83: return false;
84: }
85:
86: }
|