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.util.Locale;
23
24 import org.codehaus.plexus.logging.AbstractLoggerManager;
25 import org.codehaus.plexus.logging.Logger;
26 import org.codehaus.plexus.logging.LoggerManager;
27 import org.codehaus.plexus.logging.console.ConsoleLogger;
28 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class MavenLoggerManager
47 extends AbstractLoggerManager
48 implements LoggerManager, Initializable
49 {
50
51
52
53
54
55
56 private String threshold = "info";
57
58 private int currentThreshold;
59
60 private Logger logger;
61
62 public MavenLoggerManager( Logger logger )
63 {
64 this.logger = logger;
65 }
66
67 public void initialize()
68 {
69 debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
70
71 currentThreshold = parseThreshold( threshold );
72
73 if ( currentThreshold == -1 )
74 {
75 debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." );
76 currentThreshold = Logger.LEVEL_DEBUG;
77 }
78 }
79
80 public void setThreshold( int currentThreshold )
81 {
82 this.currentThreshold = currentThreshold;
83 }
84
85 public void setThresholds( int currentThreshold )
86 {
87 this.currentThreshold = currentThreshold;
88
89 logger.setThreshold( currentThreshold );
90 }
91
92
93 public int getThreshold()
94 {
95 return currentThreshold;
96 }
97
98 public void setThreshold( String role,
99 String roleHint,
100 int threshold )
101 {
102 }
103
104 public int getThreshold( String role,
105 String roleHint )
106 {
107 return currentThreshold;
108 }
109
110 public Logger getLoggerForComponent( String role,
111 String roleHint )
112 {
113 return logger;
114 }
115
116 public void returnComponentLogger( String role,
117 String roleHint )
118 {
119 }
120
121 public int getActiveLoggerCount()
122 {
123 return 1;
124 }
125
126 private int parseThreshold( String text )
127 {
128 text = text.trim().toLowerCase( Locale.ENGLISH );
129
130 if ( text.equals( "debug" ) )
131 {
132 return ConsoleLogger.LEVEL_DEBUG;
133 }
134 else if ( text.equals( "info" ) )
135 {
136 return ConsoleLogger.LEVEL_INFO;
137 }
138 else if ( text.equals( "warn" ) )
139 {
140 return ConsoleLogger.LEVEL_WARN;
141 }
142 else if ( text.equals( "error" ) )
143 {
144 return ConsoleLogger.LEVEL_ERROR;
145 }
146 else if ( text.equals( "fatal" ) )
147 {
148 return ConsoleLogger.LEVEL_FATAL;
149 }
150
151 return -1;
152 }
153
154
155
156
157
158
159 private void debug( String msg )
160 {
161 }
162 }