KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > log > SyslogHandler


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

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 JavaDoc;
36 import java.util.logging.LogRecord JavaDoc;
37
38 /**
39  * Logs to the syslog stream
40  */

41 public class SyslogHandler extends Handler JavaDoc {
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   /**
52    * Sets the facility.
53    */

54   public void setFacility(String JavaDoc 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   /**
99    * Sets the severity.
100    */

101   public void setSeverity(String JavaDoc 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   /**
126    * Publishes the record.
127    */

128   public void publish(LogRecord JavaDoc record)
129   {
130     if (record.getLevel().intValue() < getLevel().intValue())
131       return;
132
133     Syslog.syslog(_facility, _severity, record.getMessage());
134   }
135
136   /**
137    * Flushes the buffer.
138    */

139   public void flush()
140   {
141   }
142
143   /**
144    * Closes the handler.
145    */

146   public void close()
147   {
148   }
149 }
150
Popular Tags