Clover Coverage Report - Kuali Maven Common 1.0.5-SNAPSHOT
Coverage timestamp: Sun Feb 6 2011 14:33:42 EST
../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
56   212   44   2.07
26   158   0.79   27
27     1.63  
1    
 
  MavenLogger       Line # 15 56 0% 44 109 0% 0.0
 
No Tests
 
1    package org.kuali.maven.mojo;
2   
3    import org.apache.commons.logging.Log;
4    import org.apache.log4j.AppenderSkeleton;
5    import org.apache.log4j.Level;
6    import org.apache.log4j.spi.LoggingEvent;
7    import org.apache.maven.plugin.AbstractMojo;
8    import org.apache.maven.plugin.logging.SystemStreamLog;
9   
10    /**
11    * A utility class that sets up logging for maven plugins so that any logging calls issued via Jakarta's Commons Logging
12    * or Log4j get routed through the maven logging system. This allows mojo's to invoke logic from other libraries and get
13    * the logging statements issued by those libraries issued to maven's console output
14    */
 
15    public class MavenLogger extends AppenderSkeleton implements Log {
16   
17    private static org.apache.maven.plugin.logging.Log systemStreamLog = new SystemStreamLog();
18    private static org.apache.maven.plugin.logging.Log mavenLog = systemStreamLog;
19   
 
20  0 toggle public MavenLogger() {
21  0 this(null);
22    }
23   
24    /**
25    * Jakarta Commons Logging requires a constructor that takes a string
26    */
 
27  0 toggle public MavenLogger(final String name) {
28  0 super();
29    }
30   
31    /**
32    * Start logging for this plugin
33    */
 
34  0 toggle public static void startPluginLog(final AbstractMojo mojo) {
35  0 mavenLog = mojo.getLog();
36    }
37   
38    /**
39    * End logging for this plugin
40    */
 
41  0 toggle public static void endPluginLog(final AbstractMojo mojo) {
42  0 mavenLog = systemStreamLog;
43    }
44   
45    // Log4j methods
46   
 
47  0 toggle protected Throwable getThrowable(final LoggingEvent event) {
48  0 if (event.getThrowableInformation() == null) {
49  0 return null;
50    }
51  0 return event.getThrowableInformation().getThrowable();
52    }
53   
 
54  0 toggle @Override
55    protected void append(final LoggingEvent event) {
56  0 Level level = event.getLevel();
57  0 if (Level.DEBUG.equals(level) && !(mavenLog.isDebugEnabled())) {
58  0 return;
59    }
60   
61  0 if (Level.TRACE.equals(level) && !(mavenLog.isDebugEnabled())) {
62  0 return;
63    }
64   
65  0 String text = this.layout.format(event);
66  0 Throwable throwable = getThrowable(event);
67  0 if (Level.DEBUG.equals(level) || Level.TRACE.equals(level)) {
68  0 if (throwable == null) {
69  0 debug(text);
70    } else {
71  0 debug(text, throwable);
72    }
73  0 } else if (Level.INFO.equals(level)) {
74  0 if (throwable == null) {
75  0 info(text);
76    } else {
77  0 info(text, throwable);
78    }
79  0 } else if (Level.WARN.equals(level)) {
80  0 if (throwable == null) {
81  0 warn(text);
82    } else {
83  0 warn(text, throwable);
84    }
85  0 } else if (Level.ERROR.equals(level) || Level.FATAL.equals(level)) {
86  0 if (throwable == null) {
87  0 error(text);
88    } else {
89  0 error(text, throwable);
90    }
91    } else {
92  0 if (throwable == null) {
93  0 error(text);
94    } else {
95  0 error(text, throwable);
96    }
97    }
98    }
99   
 
100  0 toggle @Override
101    public void close() {
102  0 mavenLog = null;
103    }
104   
 
105  0 toggle @Override
106    public boolean requiresLayout() {
107  0 return true;
108    }
109   
110    // Jakarta Commons Logging methods
 
111  0 toggle @Override
112    public boolean isDebugEnabled() {
113  0 return mavenLog.isDebugEnabled();
114    }
115   
 
116  0 toggle @Override
117    public boolean isErrorEnabled() {
118  0 return mavenLog.isErrorEnabled();
119    }
120   
 
121  0 toggle @Override
122    public boolean isFatalEnabled() {
123  0 return mavenLog.isErrorEnabled();
124    }
125   
 
126  0 toggle @Override
127    public boolean isInfoEnabled() {
128  0 return mavenLog.isInfoEnabled();
129    }
130   
 
131  0 toggle @Override
132    public boolean isTraceEnabled() {
133  0 return mavenLog.isDebugEnabled();
134    }
135   
 
136  0 toggle @Override
137    public boolean isWarnEnabled() {
138  0 return mavenLog.isWarnEnabled();
139    }
140   
 
141  0 toggle @Override
142    public void trace(final Object message) {
143  0 mavenLog.debug(getString(message));
144    }
145   
 
146  0 toggle @Override
147    public void trace(final Object message, final Throwable t) {
148  0 mavenLog.debug(getString(message), t);
149   
150    }
151   
 
152  0 toggle @Override
153    public void debug(final Object message) {
154  0 mavenLog.debug(getString(message));
155    }
156   
 
157  0 toggle @Override
158    public void debug(final Object message, final Throwable t) {
159  0 mavenLog.debug(getString(message), t);
160    }
161   
 
162  0 toggle @Override
163    public void info(final Object message) {
164  0 mavenLog.info(getString(message));
165    }
166   
 
167  0 toggle @Override
168    public void info(final Object message, final Throwable t) {
169  0 mavenLog.info(getString(message), t);
170    }
171   
 
172  0 toggle @Override
173    public void warn(final Object message) {
174  0 mavenLog.warn(getString(message));
175    }
176   
 
177  0 toggle @Override
178    public void warn(final Object message, final Throwable t) {
179  0 mavenLog.warn(getString(message), t);
180    }
181   
 
182  0 toggle @Override
183    public void error(final Object message) {
184  0 mavenLog.error(getString(message));
185    }
186   
 
187  0 toggle @Override
188    public void error(final Object message, final Throwable t) {
189  0 mavenLog.error(getString(message), t);
190    }
191   
 
192  0 toggle @Override
193    public void fatal(final Object message) {
194  0 mavenLog.error(getString(message));
195    }
196   
 
197  0 toggle @Override
198    public void fatal(final Object message, final Throwable t) {
199  0 mavenLog.error(getString(message), t);
200    }
201   
202    /**
203    * Check for null then call toString on the object
204    */
 
205  0 toggle protected String getString(final Object message) {
206  0 if (message == null) {
207  0 return null;
208    }
209  0 return message.toString();
210    }
211   
212    }