Changeset 13566


Ignore:
Timestamp:
2007-01-11T13:28:53+13:00 (15 years ago)
Author:
shaoqun
Message:

added a logger, the class doesnot work on windows because the readline loop cannot be terminated by null

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/server/StreamGobbler.java

    r13229 r13566  
    66import java.io.InputStreamReader;
    77
    8 class StreamGobbler extends Thread {
    9     InputStream is;
    10     String type;
     8import org.apache.log4j.*;
     9
     10class StreamGobbler{
     11    static Logger logger = Logger.getLogger(org.greenstone.server.StreamGobbler.class.getName());
    1112   
    12     StreamGobbler(InputStream is, String type) {
    13     this.is = is;
    14     this.type = type;
    15     }
     13    public static void logError(InputStream in)
     14      {
     15      try {
     16          BufferedReader br = new BufferedReader(new InputStreamReader(in));
     17          String line = null;
     18              //using null as a guard doesn't work on windows
     19          while ((line = br.readLine()) != null){
     20          logger.error(line);
     21          }
     22      } catch (IOException ioe) {
     23          logger.error(ioe);
     24      }
     25      }
    1626   
    17     public void run() {
     27   
     28    public void logInfo(InputStream in){
    1829    try {
    19         InputStreamReader isr = new InputStreamReader(is);
    20         BufferedReader br = new BufferedReader(isr);
     30        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    2131        String line = null;
    22         while ((line = br.readLine()) != null)
    23         System.out.println(type + ">" + line);
    24     } catch (IOException ioe) {
    25         ioe.printStackTrace();
    26     }
     32        while ((line = br.readLine()) != null){
     33          logger.info(line);
     34          }
     35      } catch (IOException ioe) {
     36          logger.error(ioe);
     37      }
    2738    }
    2839}
Note: See TracChangeset for help on using the changeset viewer.