001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.log;
030:
031: import com.caucho.config.ConfigException;
032: import com.caucho.util.L10N;
033: import com.caucho.vfs.Syslog;
034:
035: import java.util.logging.Handler;
036: import java.util.logging.LogRecord;
037:
038: /**
039: * Logs to the syslog stream
040: */
041: public class SyslogHandler extends Handler {
042: private static L10N L = new L10N(SyslogHandler.class);
043:
044: private int _facility = Syslog.LOG_DAEMON;
045: private int _severity = Syslog.LOG_INFO;
046:
047: public SyslogHandler() {
048: }
049:
050: /**
051: * Sets the facility.
052: */
053: public void setFacility(String facility) throws ConfigException {
054: if ("user".equals(facility))
055: _facility = Syslog.LOG_USER;
056: else if ("mail".equals(facility))
057: _facility = Syslog.LOG_MAIL;
058: else if ("daemon".equals(facility))
059: _facility = Syslog.LOG_DAEMON;
060: else if ("auth".equals(facility))
061: _facility = Syslog.LOG_AUTH;
062: else if ("lpr".equals(facility))
063: _facility = Syslog.LOG_LPR;
064: else if ("news".equals(facility))
065: _facility = Syslog.LOG_NEWS;
066: else if ("uucp".equals(facility))
067: _facility = Syslog.LOG_UUCP;
068: else if ("cron".equals(facility))
069: _facility = Syslog.LOG_CRON;
070: else if ("authpriv".equals(facility))
071: _facility = Syslog.LOG_AUTHPRIV;
072: else if ("ftp".equals(facility))
073: _facility = Syslog.LOG_FTP;
074: else if ("local0".equals(facility))
075: _facility = Syslog.LOG_LOCAL0;
076: else if ("local1".equals(facility))
077: _facility = Syslog.LOG_LOCAL1;
078: else if ("local2".equals(facility))
079: _facility = Syslog.LOG_LOCAL2;
080: else if ("local3".equals(facility))
081: _facility = Syslog.LOG_LOCAL3;
082: else if ("local4".equals(facility))
083: _facility = Syslog.LOG_LOCAL4;
084: else if ("local5".equals(facility))
085: _facility = Syslog.LOG_LOCAL5;
086: else if ("local6".equals(facility))
087: _facility = Syslog.LOG_LOCAL6;
088: else if ("local7".equals(facility))
089: _facility = Syslog.LOG_LOCAL7;
090: else
091: throw new ConfigException(L.l(
092: "'{0}' is an unknown syslog facility.", facility));
093: }
094:
095: /**
096: * Sets the severity.
097: */
098: public void setSeverity(String severity) throws ConfigException {
099: if ("emerg".equals(severity))
100: _facility = Syslog.LOG_EMERG;
101: else if ("alert".equals(severity))
102: _facility = Syslog.LOG_ALERT;
103: else if ("crit".equals(severity))
104: _facility = Syslog.LOG_CRIT;
105: else if ("err".equals(severity))
106: _facility = Syslog.LOG_ERR;
107: else if ("warning".equals(severity))
108: _facility = Syslog.LOG_WARNING;
109: else if ("notice".equals(severity))
110: _facility = Syslog.LOG_NOTICE;
111: else if ("info".equals(severity))
112: _facility = Syslog.LOG_INFO;
113: else if ("debug".equals(severity))
114: _facility = Syslog.LOG_DEBUG;
115: else
116: throw new ConfigException(L.l(
117: "'{0}' is an unknown syslog severity.", severity));
118: }
119:
120: /**
121: * Publishes the record.
122: */
123: public void publish(LogRecord record) {
124: if (record.getLevel().intValue() < getLevel().intValue())
125: return;
126:
127: Syslog.syslog(_facility, _severity, record.getMessage());
128: }
129:
130: /**
131: * Flushes the buffer.
132: */
133: public void flush() {
134: }
135:
136: /**
137: * Closes the handler.
138: */
139: public void close() {
140: }
141: }
|