|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService SK.gnome.dwarf.thread.ThreadService SK.gnome.dwarf.log.GenericLogger SK.gnome.dwarf.log.SyslogLogger
The syslog logger.
This logger forwards the log messages to a syslog server. The syslog server is a standard TCP/IP network service described by the RFC 3164. It listens on UDP port 514 for incoming event notification messages, collects them and either writes to a physical medium or forwards to another syslog server.
The address of the remote syslog server can be specified via the setAddress(InetAddress)
method. The setFacility(int)
method specifies the facility of the generated syslog
messages. The default facility is local0, but you may use another facility, if desired.
See the write(long, String, LogLevel, String, Throwable)
method for detailed
information about the logging process.
Field Summary | |
protected java.net.InetAddress |
address
The address of the remote syslog server. |
protected int |
facility
The facility of generated syslog messages. |
protected boolean |
hostname
Whether to send the HOSTNAME header field. |
protected int |
port
The UDP port on the remote syslog server. |
protected java.net.DatagramSocket |
socket
The datagram socket for sending the messages. |
Fields inherited from class SK.gnome.dwarf.log.GenericLogger |
facilities, levels, lock, LOG_FACILITY_ALL |
Fields inherited from class SK.gnome.dwarf.thread.ThreadService |
daemon, thread |
Fields inherited from class SK.gnome.dwarf.GenericService |
initParameters, parent |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
SyslogLogger(java.lang.String name)
Creates a new SyslogLogger. |
Method Summary | |
void |
init(Server parent)
Inititalizes the service. |
void |
setAddress(java.net.InetAddress address)
Sets the address of the remote syslog server. |
void |
setFacility(int facility)
Sets the facility of the generated syslog messages. |
void |
setPort(int port)
Sets the UDP port of the remote syslog server. |
void |
setSendHostname(boolean enable)
Enables or disables sending of HOSTNAME field in the header. |
void |
shutdown()
Shuts down the service and closes the datagram socket. |
protected boolean |
wouldLog(java.lang.String facility,
LogLevel level)
Decides whether the logger would log a message with the given loggging level and facility. |
protected void |
write(long time,
java.lang.String facility,
LogLevel level,
java.lang.String message,
java.lang.Throwable error)
Sends the message to the syslog server. |
Methods inherited from class SK.gnome.dwarf.log.GenericLogger |
enableThread, getLastAccessed, log, log, loop, setFacilities, setLevels, setMarkInterval, setRepeatedInterval, start |
Methods inherited from class SK.gnome.dwarf.thread.ThreadService |
finish, run, setDaemon, stop |
Methods inherited from class SK.gnome.dwarf.GenericService |
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.net.DatagramSocket socket
It is initialized in the init(Server)
method. The access to the socket
must be synchronized.
protected java.net.InetAddress address
setAddress(InetAddress)
protected int port
Default: 514
setPort(int)
protected int facility
Default: 16
setFacility(int)
protected boolean hostname
Default: true
setSendHostname(boolean)
Constructor Detail |
public SyslogLogger(java.lang.String name)
Method Detail |
public void setAddress(java.net.InetAddress address)
This is the address of the syslog server the messages will be routed to.
address
- the inet addressaddress
public void setPort(int port)
Normally, the default UDP port number 514 is used for the syslog service. You should never change this value.
port
- the port numberport
public void setFacility(int facility)
Typically, one of the local use facilities or the user level facility should be used by the services which have not been assigned a concrete facility number. The following facilities are defined byt the RFC 3164:
Numerical Facility Code 0 kernel messages 1 user-level messages 2 mail system 3 system daemons 4 security/authorization messages (note 1) 5 messages generated internally by syslogd 6 line printer subsystem 7 network news subsystem 8 UUCP subsystem 9 clock daemon (note 2) 10 security/authorization messages (note 1) 11 FTP daemon 12 NTP subsystem 13 log audit (note 1) 14 log alert (note 1) 15 clock daemon (note 2) 16 local use 0 (local0) 17 local use 1 (local1) 18 local use 2 (local2) 19 local use 3 (local3) 20 local use 4 (local4) 21 local use 5 (local5) 22 local use 6 (local6) 23 local use 7 (local7)
The SyslogLogger uses local0 facility by default.
facility
- the facility codefacility
public void setSendHostname(boolean enable)
The syslog protocol description states that the HOSTNAME field should be send along with the TIMESTAMP info in the message packet header. However, some syslog servers would log this hostname information twice, so this method may be used to prevent such information redundancy. The sending of hostname is enabled by default for conformance with the RFC document.
enable
- true to enable sending of hostnamehostname
public void init(Server parent) throws ServiceException
The new DatagramSocket is created and connected to the address
and port
. The socket reference is then assigned to the socket
field.
init
in interface Service
init
in class GenericService
ServiceException
public void shutdown()
shutdown
in interface Service
shutdown
in class GenericLogger
protected boolean wouldLog(java.lang.String facility, LogLevel level)
It first checks whether the UDP socket has been initialized and then calls the overriden wouldLog method and returns its result.
wouldLog
in class GenericLogger
facility
- the logging facilitylevel
- the logging level
protected void write(long time, java.lang.String facility, LogLevel level, java.lang.String message, java.lang.Throwable error)
This method formats the message and sends it to the remote syslog server via the
socket
.
The Dwarf logging levels are mapped to severity levels defined by the protocol specification as follows:
Dwarf Syslog Severity Level Code LOG_FATAL =< 0 Emergency: system is unusable 1 Alert: action must be taken immediately 2 Critical: critical conditions LOG_ERROR =< 3 Error: error conditions LOG_WARN =< 4 Warning: warning conditions 5 Notice: normal but significant condition LOG_INFO =< 6 Informational: informational messages LOG_DEBUG =< 7 Debug: debug-level messages
Since the length of a syslog datagram packet is limited to 1024 bytes, any messages longer than this limit will be truncated to 1kB automatically.
write
in class GenericLogger
time
- the current time of the logged eventfacility
- the log facilitylevel
- the log levelmessage
- the messageerror
- the error (optional)GenericLogger.log(String, LogLevel, String)
,
GenericLogger.log(String, LogLevel, String, Throwable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |