1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import org.codehaus.plexus.util.cli.StreamConsumer;
19 import org.slf4j.Logger;
20
21 public class LoggingStreamConsumer implements StreamConsumer {
22
23 Logger logger;
24 LoggerLevel level;
25
26 public LoggingStreamConsumer() {
27 this(null);
28 }
29
30 public LoggingStreamConsumer(Logger logger) {
31 this(logger, LoggerLevel.INFO);
32 }
33
34 public LoggingStreamConsumer(Logger logger, LoggerLevel level) {
35 super();
36 this.logger = logger;
37 this.level = level;
38 }
39
40 @Override
41 public void consumeLine(String line) {
42 switch (level) {
43 case TRACE:
44 logger.trace(line);
45 return;
46 case DEBUG:
47 logger.debug(line);
48 return;
49 case INFO:
50 logger.info(line);
51 return;
52 case WARN:
53 logger.warn(line);
54 return;
55 case ERROR:
56 logger.error(line);
57 return;
58 default:
59 throw new IllegalStateException("Logger level " + level + " is unknown");
60 }
61 }
62
63 public Logger getLogger() {
64 return logger;
65 }
66
67 public void setLogger(Logger logger) {
68 this.logger = logger;
69 }
70
71 public LoggerLevel getLevel() {
72 return level;
73 }
74
75 public void setLevel(LoggerLevel level) {
76 this.level = level;
77 }
78
79 }