01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.logging;
05:
06: import com.tc.util.Assert;
07:
08: import java.io.BufferedReader;
09: import java.io.IOException;
10: import java.io.InputStream;
11: import java.io.InputStreamReader;
12:
13: /**
14: * A simple thread that copies one stream to another. Useful for copying a process's output/error streams to this
15: * process's output/error streams.
16: */
17: public class TCStreamLogger extends Thread {
18:
19: protected final BufferedReader in;
20: protected final TCLogger out;
21: protected final LogLevel level;
22:
23: public TCStreamLogger(InputStream stream, TCLogger logger,
24: LogLevel level) {
25: Assert.assertNotNull(stream);
26:
27: this .in = new BufferedReader(new InputStreamReader(stream));
28: this .out = logger;
29: this .level = level;
30: }
31:
32: public void run() {
33: String line;
34: try {
35: while ((line = in.readLine()) != null) {
36: out.log(level, line);
37: }
38: } catch (IOException e) {
39: out.log(level, "Exception reading InputStream: " + e);
40: }
41: }
42:
43: }
|