KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > maven > EmbedderLoggerImpl


1 package hudson.maven;
2
3 import hudson.model.TaskListener;
4 import org.apache.maven.embedder.AbstractMavenEmbedderLogger;
5 import org.apache.maven.embedder.MavenEmbedderLogger;
6
7 import java.io.PrintStream JavaDoc;
8 import java.util.StringTokenizer JavaDoc;
9
10 /**
11  * {@link MavenEmbedderLogger} implementation that
12  * sends output to {@link TaskListener}.
13  *
14  * @author Kohsuke Kawaguchi
15  */

16 final class EmbedderLoggerImpl extends AbstractMavenEmbedderLogger {
17     private final PrintStream JavaDoc logger;
18
19     public EmbedderLoggerImpl(TaskListener listener) {
20         logger = listener.getLogger();
21     }
22
23     private void print(String JavaDoc message, Throwable JavaDoc throwable, int threshold, String JavaDoc prefix) {
24         if (getThreshold() <= threshold) {
25             StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(message,"\n");
26             while(tokens.hasMoreTokens()) {
27                 logger.print(prefix);
28                 logger.println(tokens.nextToken());
29             }
30
31             if (throwable!=null)
32                 throwable.printStackTrace(logger);
33         }
34     }
35
36     public void debug(String JavaDoc message, Throwable JavaDoc throwable) {
37         print(message, throwable, LEVEL_DEBUG, "[DEBUG] ");
38     }
39
40     public void info(String JavaDoc message, Throwable JavaDoc throwable) {
41         print(message, throwable, LEVEL_INFO, "[INFO ] ");
42     }
43
44     public void warn(String JavaDoc message, Throwable JavaDoc throwable) {
45         print(message, throwable, LEVEL_WARN, "[WARN ] ");
46     }
47
48     public void error(String JavaDoc message, Throwable JavaDoc throwable) {
49         print(message, throwable, LEVEL_ERROR, "[ERROR] ");
50     }
51
52     public void fatalError(String JavaDoc message, Throwable JavaDoc throwable) {
53         print(message, throwable, LEVEL_FATAL, "[FATAL] ");
54     }
55 }
56
Popular Tags