1 18 19 package org.objectweb.util.monolog.wrapper.log4jMini; 20 21 import org.apache.log4j.FileAppender; 22 import org.apache.log4j.PatternLayout; 23 import org.objectweb.util.monolog.api.Handler; 24 25 import java.io.IOException ; 26 import java.util.Hashtable ; 27 import java.util.Enumeration ; 28 29 34 public class FileHandler extends FileAppender implements Handler { 35 36 protected byte type = 0; 37 protected Hashtable props = null; 38 39 46 public FileHandler(byte type, String name) { 47 super(); 48 this.type = type; 49 setName(name); 50 props = new Hashtable (3); 51 } 52 53 56 public String getType() { 57 return "file"; 58 } 59 60 public String [] getAttributeNames() { 61 String [] res = new String [props.size()]; 62 int i=0; 63 for(Enumeration en=props.keys(); en.hasMoreElements();) { 64 res[i++] = (String ) en.nextElement(); 65 } 66 return res; 67 } 68 69 public Object getAttribute(String key) { 70 return props.get(key); 71 } 72 73 public Object setAttribute(String key, Object value) { 74 props.put(key, value); 75 if (key.equalsIgnoreCase(Handler.OUTPUT_ATTRIBUTE)) { 76 if ("console".equalsIgnoreCase(type)) { 77 setOption(FILE_OPTION, (String ) value); 78 } else if ("file".equalsIgnoreCase(type)) { 79 try { 80 fileName=(String ) value; 81 setFile(fileName); 82 } catch (IOException e) { 83 e.printStackTrace(); 84 } 85 } 86 } 87 else if (key.equalsIgnoreCase(Handler.PATTERN_ATTRIBUTE)) { 88 setLayout( 89 new PatternLayout( 90 PatternConverter.monolog2log4j((String ) value))); 91 } 92 else if (key.equalsIgnoreCase(Handler.APPEND_MODE_ATTRIBUTE)) { 93 setOption(APPEND_OPTION, (String ) value); 94 fileAppend = new Boolean ( (String ) value).booleanValue(); 95 101 } 102 return null; 103 } 104 } 105 | Popular Tags |