-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTDIORedirectToLog4j.java
More file actions
56 lines (45 loc) · 1.05 KB
/
STDIORedirectToLog4j.java
File metadata and controls
56 lines (45 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.animetrics.utils;
import org.apache.log4j.Logger;
public class STDIORedirectToLog4j extends Thread {
private final STDIORedirectNative srNative;
private final Logger log;
private final int fileno;
public STDIORedirectToLog4j(int fileno)
{
this.fileno = fileno;
this.srNative = new STDIORedirectNative(this.fileno);
this.log = Logger.getLogger("STDIO");
}
public void run()
{
String s = new String();
try
{
while (true)
{
s = this.srNative.read();
if(0 == s.length())
break;
// since logger adds a new line, remove trailing new line
s = s.replaceAll("[\r]?[\n]?$", "");
// if we are left with an empty string, don't print
if(s.length() > 0)
{
if(1 == this.fileno)
this.log.info(s);
else
this.log.error(s);
}
}
}
catch (Exception ex)
{
this.srNative.close();
ex.printStackTrace();
}
finally
{
this.srNative.close();
}
}
}