1 19 package net.sf.jbatchengine.batch.util; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 26 import org.apache.log4j.Logger; 27 28 34 public class LogRedirectionThread extends Thread { 35 36 37 private static transient Logger log = Logger.getLogger(LogRedirectionThread.class); 38 39 40 private Process proc; 41 42 43 private int usage; 44 45 46 public final static int OUT = 1; 47 48 49 public final static int ERR = 2; 50 51 57 public LogRedirectionThread(Process proc, int usage) { 58 this.proc = proc; 59 this.usage = usage; 60 } 61 62 65 public void run() { 66 try { 67 InputStream is = null; 68 69 if (this.usage == OUT) { 70 is = proc.getInputStream(); 71 } 72 else { 73 is = proc.getErrorStream(); 74 } 75 76 BufferedReader br = new BufferedReader (new InputStreamReader (is)); 77 String msg = br.readLine(); 78 while (msg != null) { 79 if (this.usage == OUT) { 80 log.info(msg); 81 } 82 else { 83 log.error(msg); 84 } 85 msg = br.readLine(); 86 } 87 } 88 catch (IOException e) { 89 e.printStackTrace(); 90 } 91 } 92 } 93 | Popular Tags |