Main: Whitepaper FAQ Examples JavaDoc Classloader Performance
Protomatter Software v1.1.8

com.protomatter.syslog
Class UNIXSyslogLog

java.lang.Object
  |
  +--com.protomatter.syslog.BasicLogger
        |
        +--com.protomatter.syslog.UNIXSyslogLog
All Implemented Interfaces:
Syslogger

public class UNIXSyslogLog
extends BasicLogger

A logger that sends UDP packets to a UNIX syslog server. This logger sends UDP packets to UNIX servers running a BSD-style syslogd daemon. Refer to RFC 3164 for information about the protocol.

With the default formatting options, a call to Syslog.info(this, "Hello there") will result in the following to be written to /var/log/messages (or its equivalent) on the UNIX box:

This assumes you logged from a class called MyClass, that you havn't set the tag to some more meaningful value, and that your hostname is "sillysailor".

See Also:
XML configuration class

Field Summary
static java.lang.String CALLER_TOKEN
           
static java.lang.String CHANNEL_TOKEN
           
static java.util.Map DEFAULT_SEVERITY_MAP
          The default severity map.
static java.lang.String FULLCALLER_TOKEN
           
static java.lang.String MESSAGE_TOKEN
           
static java.lang.String SEVERITY_TOKEN
           
static java.lang.String THREAD_TOKEN
           
static int UNIX_ALERT
          Alert: take action immediately (RFC 3164).
static int UNIX_CRITICAL
          Critical: critical conitions (RFC 3164).
static int UNIX_DEBUG
          Debug: debug-level messages (RFC 3164).
static int UNIX_EMERGENCY
          Emergency: system is unusable (RFC 3164).
static int UNIX_ERROR
          Error: error conditions (RFC 3164).
static int UNIX_INFO
          Informational: informational messages (RFC 3164).
static int UNIX_NOTICE
          Notice: normal but significant (RFC 3164).
static int UNIX_WARNING
          Warning: warning conditions (RFC 3164).
 
Fields inherited from class com.protomatter.syslog.BasicLogger
formatter, policy, realPolicy
 
Constructor Summary
UNIXSyslogLog()
          Create a new UNIX logger with no settings.
UNIXSyslogLog(java.net.InetAddress address)
          Create a new UNIX logger sending messages to the given host on the default syslog port (514).
UNIXSyslogLog(java.net.InetAddress address, int port)
          Create a new UNIX logger sending messages to the given host and port.
 
Method Summary
 void flush()
          Flush the given logger's output.
 int getFacility()
          Get the facility ID that messages appear to be from.
 java.net.InetAddress getLogServer()
          Get the address of the log server.
 java.lang.String getMessageTemplate()
          Get the text template used to format part of the packet body.
 int getPort()
          Get the port number on the log server.
 java.util.Map getSeverityMap()
          Get the map to use when converting Syslog severities into UNIX severities.
protected  java.lang.String getSeverityName(int syslogSeverity)
           
 boolean getShowHostname()
          Determine if we should show the hostname before the "tag".
 java.lang.String getTag()
          Get the tag that messages appear as.
 void log(SyslogMessage message)
          Log a message.
 void setFacility(int facility)
          Set the facility ID that messages appear to be from.
 void setLogServer(java.net.InetAddress address)
          Set the address of the log server.
 void setMessageTemplate(java.lang.String template)
          Set the message body formatting template.
 void setPort(int port)
          Set the port number on the log server.
 void setSeverityMap(java.util.Map map)
          Set the map to use when converting Syslog severities into UNIX severities.
 void setShowHostname(boolean showHostname)
          Set if we should show the hostname before the "tag".
 void setTag(java.lang.String tag)
          Set the tag that messages appear as.
 void shutdown()
          Shutdown this logger.
 
Methods inherited from class com.protomatter.syslog.BasicLogger
formatLogEntry, getName, getPolicy, getTextFormatter, isSuspended, mightLog, resetDateFormat, resume, setName, setPolicy, setTextFormatter, shouldLog, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANNEL_TOKEN

public static final java.lang.String CHANNEL_TOKEN

FULLCALLER_TOKEN

public static final java.lang.String FULLCALLER_TOKEN

CALLER_TOKEN

public static final java.lang.String CALLER_TOKEN

MESSAGE_TOKEN

public static final java.lang.String MESSAGE_TOKEN

THREAD_TOKEN

public static final java.lang.String THREAD_TOKEN

SEVERITY_TOKEN

public static final java.lang.String SEVERITY_TOKEN

UNIX_DEBUG

public static final int UNIX_DEBUG
Debug: debug-level messages (RFC 3164).

UNIX_INFO

public static final int UNIX_INFO
Informational: informational messages (RFC 3164).

UNIX_NOTICE

public static final int UNIX_NOTICE
Notice: normal but significant (RFC 3164).

UNIX_WARNING

public static final int UNIX_WARNING
Warning: warning conditions (RFC 3164).

UNIX_ERROR

public static final int UNIX_ERROR
Error: error conditions (RFC 3164).

UNIX_CRITICAL

public static final int UNIX_CRITICAL
Critical: critical conitions (RFC 3164).

UNIX_ALERT

public static final int UNIX_ALERT
Alert: take action immediately (RFC 3164).

UNIX_EMERGENCY

public static final int UNIX_EMERGENCY
Emergency: system is unusable (RFC 3164).

DEFAULT_SEVERITY_MAP

public static java.util.Map DEFAULT_SEVERITY_MAP
The default severity map.
Constructor Detail

UNIXSyslogLog

public UNIXSyslogLog(java.net.InetAddress address,
                     int port)
              throws SyslogInitException
Create a new UNIX logger sending messages to the given host and port.

UNIXSyslogLog

public UNIXSyslogLog(java.net.InetAddress address)
              throws SyslogInitException
Create a new UNIX logger sending messages to the given host on the default syslog port (514).

UNIXSyslogLog

public UNIXSyslogLog()
              throws SyslogInitException
Create a new UNIX logger with no settings. You must call setLogServer() at least before trying to use this.
Method Detail

setMessageTemplate

public void setMessageTemplate(java.lang.String template)
Set the message body formatting template. This string is used to format the body of the UDP packet in conjunction with the java.text.MessageFormat class. The following tokens are replaced in the String during formatting:

{CHANNEL}Channel name
{CALLER-FULLNAME}Full caller class name (with package)
{CALLER}Caller class name
{MESSAGE}Short message
{THREAD}Thread name
{SEVERITY}Severity ("DEBUG" ... "FATAL")

The default value is "[{SEVERITY}] {CALLER}: {MESSAGE}". You can set this to something like "{CHANNEL}: {CALLER}: {MESSAGE}" or "{CALLER}: [{CHANNEL}] {MESSAGE}" as examples to see what you can do with this.


getMessageTemplate

public java.lang.String getMessageTemplate()
Get the text template used to format part of the packet body.

setSeverityMap

public void setSeverityMap(java.util.Map map)
Set the map to use when converting Syslog severities into UNIX severities. The key in the map should be a java.lang.Integer representing the Syslog severity (Syslog.DEBUG ... Syslog.FATAL), and the value should be a java.lang.Integer representing the UNIX severity to use for the given Syslog severity. The values for UNIX severities are described in RFC 3164, and are represented as static members of this class (UNIXSyslogLog.UNIX_DEBUG ... UNIXSyslogLog.UNIX_EMERGENCY).

getSeverityMap

public java.util.Map getSeverityMap()
Get the map to use when converting Syslog severities into UNIX severities.

getTag

public java.lang.String getTag()
Get the tag that messages appear as. Default is "ProtomatterSyslog".

setTag

public void setTag(java.lang.String tag)
Set the tag that messages appear as.

getShowHostname

public boolean getShowHostname()
Determine if we should show the hostname before the "tag". Default is "false" The spec says that you should do this, but when I tested under Red Hat Linux 7.2, it just repeated the hostname. Your mileage may vary. The default is false.

setShowHostname

public void setShowHostname(boolean showHostname)
Set if we should show the hostname before the "tag".

setFacility

public void setFacility(int facility)
Set the facility ID that messages appear to be from. Refer to RFC 3164 for more information. Here is the list:

0kernel messages
1user-level messages
2mail system
3system daemons
4security/authorization messages (note 1)
5messages generated internally by syslogd
6line printer subsystem
7network news subsystem
8UUCP subsystem
9clock daemon (note 2)
10security/authorization messages (note 1)
11FTP daemon
12NTP subsystem
13log audit (note 1)
14log alert (note 1)
15clock daemon (note 2)
16local use 0 (local0)
17local use 1 (local1)
18local use 2 (local2)
19local use 3 (local3)
20local use 4 (local4)
21local use 5 (local5)
22local use 6 (local6)
23local use 7 (local7)

Note 1: Various operating systems have been found to utilize Facilities 4, 10, 13 and 14 for security/authorization, audit, and alert messages which seem to be similar.

Note 2: Various operating systems have been found to utilize both Facilities 9 and 15 for clock (cron/at) messages.

The default is 16 (Local Use 0).


getFacility

public int getFacility()
Get the facility ID that messages appear to be from.

setLogServer

public void setLogServer(java.net.InetAddress address)
Set the address of the log server.

getLogServer

public java.net.InetAddress getLogServer()
Get the address of the log server.

setPort

public void setPort(int port)
Set the port number on the log server.

getPort

public int getPort()
Get the port number on the log server.

log

public final void log(SyslogMessage message)
Log a message.

getSeverityName

protected java.lang.String getSeverityName(int syslogSeverity)

shutdown

public void shutdown()
Description copied from interface: Syslogger
Shutdown this logger. The implementation should clean up any resources it has allocated, etc. After this method is called, no more log messages will be sent to this logger. However, if the logger receives messages after the shutdown() method is called, it can assume that logging has resumed. This method is called after the "master switch" inside Syslog has been flipped to "off" in the Syslog.shutdown() method.

flush

public void flush()
Description copied from interface: Syslogger
Flush the given logger's output.

Protomatter Software v1.1.8
Copyright 1998-2002 Nate Sammons

Protomatter Software v1.1.8 http://protomatter.sourceforge.net/1.1.8