1 9 package org.jboss.portal.common.logging; 10 11 import org.apache.log4j.Logger; 12 import org.apache.log4j.Level; 13 14 import java.io.Writer ; 15 import java.io.IOException ; 16 17 21 public class Log4JWriter extends Writer 22 { 23 24 25 private boolean open; 26 27 28 private Logger log; 29 30 31 private Level level; 32 33 36 public Log4JWriter(Logger log, Level level) throws IllegalArgumentException 37 { 38 if (log == null) 39 { 40 throw new IllegalArgumentException ("No logger provided"); 41 } 42 if (level == null) 43 { 44 throw new IllegalArgumentException ("No level provided"); 45 } 46 this.open = false; 47 this.log = log; 48 this.level = level; 49 } 50 51 public void write(char cbuf[], int off, int len) throws IOException 52 { 53 if (open) 54 { 55 log.log(level, new String (cbuf, off, len)); 56 } 57 else 58 { 59 throw new IOException ("Stream closed"); 60 } 61 } 62 63 public void flush() throws IOException 64 { 65 } 66 67 public void close() throws IOException 68 { 69 open = false; 70 } 71 } 72 | Popular Tags |