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