1 4 5 package org.objectweb.util.monolog.wrapper.log4j; 6 7 import org.apache.log4j.nt.NTEventLogAppender; 8 import org.apache.log4j.PatternLayout; 9 import org.objectweb.util.monolog.api.Handler; 10 import org.objectweb.util.monolog.wrapper.log4j.PatternConverter; 11 import org.objectweb.util.monolog.api.MonologFactory; 12 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 23 public class NTEventLogHandler extends NTEventLogAppender implements Handler { 24 25 28 protected HashMap prop = null; 29 30 public NTEventLogHandler() { 31 super(); 32 } 33 34 39 public NTEventLogHandler(String name) { 40 super(); 41 setName(name); 42 prop = new HashMap (); 43 } 44 45 public Map getAttributes() { 46 return prop; 47 } 48 49 public void setAttributes(Map attributes) { 50 prop.clear(); 51 prop.putAll(attributes); 52 Object mf = prop.get("activation"); 53 if (mf != null) { 54 prop.remove("activation"); 55 setAttribute("activation", mf); 56 } 57 } 58 59 62 public String getType() { 63 return "ntevent"; 64 } 65 66 public String [] getAttributeNames() { 67 return (String []) prop.keySet().toArray(new String [0]); 68 } 69 70 public Object getAttribute(String key) { 71 return prop.get(key); 72 } 73 74 public Object setAttribute(String key, Object value) { 75 if (prop == null) 76 prop = new HashMap (); 77 if (!key.equalsIgnoreCase("activation")) { 78 return prop.put(key, value); 79 } else if (prop.containsKey(key)) { 80 return null; } 82 MonologFactory mf = (MonologFactory) value; 83 String source = (String ) prop.get("source"); 84 if (source != null) { 85 setSource((String ) value); 86 } 87 String pattern = (String ) prop.get(Handler.PATTERN_ATTRIBUTE); 88 if (pattern != null) { 89 setLayout(new PatternLayout(PatternConverter.monolog2log4j(pattern))); 90 } 91 String level = (String ) prop.get(Handler.LEVEL_ATTRIBUTE); 92 if (level != null && level.length() > 0) { 93 int levelVal = org.objectweb.util.monolog.wrapper.common.LevelImpl.evaluate(level, mf); 94 setThreshold(org.apache.log4j.Level.toLevel(levelVal)); 95 } 96 super.activateOptions(); 97 return null; 98 } 99 } 100 | Popular Tags |