1 | |
package org.codehaus.mojo.exec; |
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 | |
import org.apache.maven.plugin.logging.Log; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
class StreamLog implements Log |
29 | |
{ |
30 | |
static final int DEBUG = 0; |
31 | |
static final int INFO = 1; |
32 | |
static final int WARN = 2; |
33 | |
static final int ERROR = 3; |
34 | |
|
35 | 0 | private int level = INFO; |
36 | |
|
37 | |
public void setLevel( int level ) |
38 | |
{ |
39 | 0 | if ( level < DEBUG || level > ERROR ) |
40 | |
{ |
41 | 0 | throw new IllegalStateException( "invalid level: " + level ); |
42 | |
} |
43 | 0 | this.level = level; |
44 | 0 | } |
45 | |
|
46 | |
private final PrintStream s; |
47 | |
|
48 | |
StreamLog( PrintStream s ) |
49 | 0 | { |
50 | 0 | this.s = s; |
51 | 0 | } |
52 | |
|
53 | |
public void debug( CharSequence content ) |
54 | |
{ |
55 | 0 | if ( isDebugEnabled() ) |
56 | |
{ |
57 | 0 | s.println( content ); |
58 | |
} |
59 | 0 | } |
60 | |
|
61 | |
public void debug( CharSequence content, Throwable error ) |
62 | |
{ |
63 | 0 | if ( isDebugEnabled() ) |
64 | |
{ |
65 | 0 | s.println( content ); |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
public void debug( Throwable error ) |
70 | |
{ |
71 | 0 | if ( isDebugEnabled() ) |
72 | |
{ |
73 | 0 | error.printStackTrace( s ); |
74 | |
} |
75 | 0 | } |
76 | |
|
77 | |
public void error( CharSequence content ) |
78 | |
{ |
79 | 0 | if ( isErrorEnabled() ) |
80 | |
{ |
81 | 0 | s.println( content ); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public void error( CharSequence content, Throwable error ) |
86 | |
{ |
87 | 0 | error( content ); |
88 | 0 | error( error ); |
89 | 0 | } |
90 | |
|
91 | |
public void error( Throwable error ) |
92 | |
{ |
93 | 0 | if ( isErrorEnabled() ) |
94 | |
{ |
95 | 0 | error.printStackTrace( s ); |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
public void info( CharSequence content ) |
100 | |
{ |
101 | 0 | if ( isInfoEnabled() ) |
102 | |
{ |
103 | 0 | s.println( content ); |
104 | |
} |
105 | 0 | } |
106 | |
|
107 | |
public void info( CharSequence content, Throwable error ) |
108 | |
{ |
109 | 0 | info( content ); |
110 | 0 | info( error ); |
111 | 0 | } |
112 | |
|
113 | |
public void info( Throwable error ) |
114 | |
{ |
115 | 0 | if ( isInfoEnabled() ) |
116 | |
{ |
117 | 0 | error.printStackTrace( s ); |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
public boolean isDebugEnabled() |
122 | |
{ |
123 | 0 | return level >= DEBUG; |
124 | |
} |
125 | |
|
126 | |
public boolean isErrorEnabled() |
127 | |
{ |
128 | 0 | return level >= ERROR; |
129 | |
} |
130 | |
|
131 | |
public boolean isInfoEnabled() |
132 | |
{ |
133 | 0 | return level >= INFO; |
134 | |
} |
135 | |
|
136 | |
public boolean isWarnEnabled() |
137 | |
{ |
138 | 0 | return level >= WARN; |
139 | |
} |
140 | |
|
141 | |
public void warn( CharSequence content ) |
142 | |
{ |
143 | 0 | if ( isWarnEnabled() ) |
144 | |
{ |
145 | 0 | s.println( content ); |
146 | |
} |
147 | 0 | } |
148 | |
|
149 | |
public void warn( CharSequence content, Throwable error ) |
150 | |
{ |
151 | 0 | warn( content ); |
152 | 0 | warn( error ); |
153 | 0 | } |
154 | |
|
155 | |
public void warn( Throwable error ) |
156 | |
{ |
157 | 0 | if ( isWarnEnabled() ) |
158 | |
{ |
159 | 0 | error.printStackTrace( s ); |
160 | |
} |
161 | 0 | } |
162 | |
} |