1 28 29 package com.caucho.log; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.L10N; 33 import com.caucho.vfs.Syslog; 34 35 import java.util.logging.Handler ; 36 import java.util.logging.LogRecord ; 37 38 41 public class SyslogHandler extends Handler { 42 private static L10N L = new L10N(SyslogHandler.class); 43 44 private int _facility = Syslog.LOG_DAEMON; 45 private int _severity = Syslog.LOG_INFO; 46 47 public SyslogHandler() 48 { 49 } 50 51 54 public void setFacility(String facility) 55 throws ConfigException 56 { 57 if ("user".equals(facility)) 58 _facility = Syslog.LOG_USER; 59 else if ("mail".equals(facility)) 60 _facility = Syslog.LOG_MAIL; 61 else if ("daemon".equals(facility)) 62 _facility = Syslog.LOG_DAEMON; 63 else if ("auth".equals(facility)) 64 _facility = Syslog.LOG_AUTH; 65 else if ("lpr".equals(facility)) 66 _facility = Syslog.LOG_LPR; 67 else if ("news".equals(facility)) 68 _facility = Syslog.LOG_NEWS; 69 else if ("uucp".equals(facility)) 70 _facility = Syslog.LOG_UUCP; 71 else if ("cron".equals(facility)) 72 _facility = Syslog.LOG_CRON; 73 else if ("authpriv".equals(facility)) 74 _facility = Syslog.LOG_AUTHPRIV; 75 else if ("ftp".equals(facility)) 76 _facility = Syslog.LOG_FTP; 77 else if ("local0".equals(facility)) 78 _facility = Syslog.LOG_LOCAL0; 79 else if ("local1".equals(facility)) 80 _facility = Syslog.LOG_LOCAL1; 81 else if ("local2".equals(facility)) 82 _facility = Syslog.LOG_LOCAL2; 83 else if ("local3".equals(facility)) 84 _facility = Syslog.LOG_LOCAL3; 85 else if ("local4".equals(facility)) 86 _facility = Syslog.LOG_LOCAL4; 87 else if ("local5".equals(facility)) 88 _facility = Syslog.LOG_LOCAL5; 89 else if ("local6".equals(facility)) 90 _facility = Syslog.LOG_LOCAL6; 91 else if ("local7".equals(facility)) 92 _facility = Syslog.LOG_LOCAL7; 93 else 94 throw new ConfigException(L.l("'{0}' is an unknown syslog facility.", 95 facility)); 96 } 97 98 101 public void setSeverity(String severity) 102 throws ConfigException 103 { 104 if ("emerg".equals(severity)) 105 _facility = Syslog.LOG_EMERG; 106 else if ("alert".equals(severity)) 107 _facility = Syslog.LOG_ALERT; 108 else if ("crit".equals(severity)) 109 _facility = Syslog.LOG_CRIT; 110 else if ("err".equals(severity)) 111 _facility = Syslog.LOG_ERR; 112 else if ("warning".equals(severity)) 113 _facility = Syslog.LOG_WARNING; 114 else if ("notice".equals(severity)) 115 _facility = Syslog.LOG_NOTICE; 116 else if ("info".equals(severity)) 117 _facility = Syslog.LOG_INFO; 118 else if ("debug".equals(severity)) 119 _facility = Syslog.LOG_DEBUG; 120 else 121 throw new ConfigException(L.l("'{0}' is an unknown syslog severity.", 122 severity)); 123 } 124 125 128 public void publish(LogRecord record) 129 { 130 if (record.getLevel().intValue() < getLevel().intValue()) 131 return; 132 133 Syslog.syslog(_facility, _severity, record.getMessage()); 134 } 135 136 139 public void flush() 140 { 141 } 142 143 146 public void close() 147 { 148 } 149 } 150 | Popular Tags |