1 package org.apache.maven.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.PrintStream;
23
24 import org.apache.maven.Maven;
25 import org.codehaus.plexus.logging.AbstractLogger;
26 import org.codehaus.plexus.logging.Logger;
27
28
29
30
31
32
33 public class PrintStreamLogger
34 extends AbstractLogger
35 {
36
37 private PrintStream out;
38
39 private static final String FATAL_ERROR = "[FATAL] ";
40
41 private static final String ERROR = "[ERROR] ";
42
43 private static final String WARNING = "[WARNING] ";
44
45 private static final String INFO = "[INFO] ";
46
47 private static final String DEBUG = "[DEBUG] ";
48
49 public PrintStreamLogger( PrintStream out )
50 {
51 super( Logger.LEVEL_INFO, Maven.class.getName() );
52
53 setStream( out );
54 }
55
56 public void setStream( PrintStream out )
57 {
58 if ( out == null )
59 {
60 throw new IllegalArgumentException( "output stream missing" );
61 }
62
63 this.out = out;
64 }
65
66 public void debug( String message, Throwable throwable )
67 {
68 if ( isDebugEnabled() )
69 {
70 out.print( DEBUG );
71 out.println( message );
72
73 if ( null != throwable )
74 {
75 throwable.printStackTrace( out );
76 }
77 }
78 }
79
80 public void info( String message, Throwable throwable )
81 {
82 if ( isInfoEnabled() )
83 {
84 out.print( INFO );
85 out.println( message );
86
87 if ( null != throwable )
88 {
89 throwable.printStackTrace( out );
90 }
91 }
92 }
93
94 public void warn( String message, Throwable throwable )
95 {
96 if ( isWarnEnabled() )
97 {
98 out.print( WARNING );
99 out.println( message );
100
101 if ( null != throwable )
102 {
103 throwable.printStackTrace( out );
104 }
105 }
106 }
107
108 public void error( String message, Throwable throwable )
109 {
110 if ( isErrorEnabled() )
111 {
112 out.print( ERROR );
113 out.println( message );
114
115 if ( null != throwable )
116 {
117 throwable.printStackTrace( out );
118 }
119 }
120 }
121
122 public void fatalError( String message, Throwable throwable )
123 {
124 if ( isFatalErrorEnabled() )
125 {
126 out.print( FATAL_ERROR );
127 out.println( message );
128
129 if ( null != throwable )
130 {
131 throwable.printStackTrace( out );
132 }
133 }
134 }
135
136 public void close()
137 {
138 if ( out == System.out || out == System.err )
139 {
140 out.flush();
141 }
142 else
143 {
144 out.close();
145 }
146 }
147
148 public Logger getChildLogger( String arg0 )
149 {
150 return this;
151 }
152
153 }