diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-11-06 23:46:39 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-11-06 23:46:39 +0000 |
commit | 36bde7b2d4e9fad082a316d562dd016a28f02c5b (patch) | |
tree | 1062df27e06651c6be6a86f1fb167cf5c9e40b4c /java/src/Ice/SysLoggerI.java | |
parent | added INSTALL.LINUX (diff) | |
download | ice-36bde7b2d4e9fad082a316d562dd016a28f02c5b.tar.bz2 ice-36bde7b2d4e9fad082a316d562dd016a28f02c5b.tar.xz ice-36bde7b2d4e9fad082a316d562dd016a28f02c5b.zip |
Added syslog logger.
Diffstat (limited to 'java/src/Ice/SysLoggerI.java')
-rw-r--r-- | java/src/Ice/SysLoggerI.java | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/java/src/Ice/SysLoggerI.java b/java/src/Ice/SysLoggerI.java new file mode 100644 index 00000000000..e8e00c989e3 --- /dev/null +++ b/java/src/Ice/SysLoggerI.java @@ -0,0 +1,115 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// ZeroC, Inc. +// Billerica, MA, USA +// +// All Rights Reserved. +// +// Ice is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// ********************************************************************** + +package Ice; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.io.IOException; + +public class SysLoggerI extends LocalObjectImpl implements Logger +{ + public + SysLoggerI(String ident) + { + _ident = ident; + + // + // Open a datagram socket to communicate with the localhost + // syslog daemon. + // + try + { + _host = InetAddress.getLocalHost(); + _socket = new DatagramSocket(); + _socket.connect(_host, _port); + } + catch(java.net.UnknownHostException ex) + { + throw new Ice.DNSException(); + } + catch(java.io.IOException ex) + { + Ice.SocketException se = new Ice.SocketException(); + se.initCause(ex); + throw se; + } + } + + public void + trace(String category, String message) + { + log(LOG_INFO, category + ": " + message); + } + + public void + warning(String message) + { + log(LOG_WARNING, message); + } + + public void + error(String message) + { + log(LOG_ERR, message); + } + + private void + log(int severity, String message) + { + try + { + // + // Create a syslog message as defined by the RFC 3164: + // <PRI>HEADER MSG. PRI is the priority and is calculated + // from the facility and the severity. We don't specify + // the HEADER. MSG contains the identifier followed by a + // colon character and the message. + // + + int priority = (LOG_USER << 3) | severity; + + String msg = '<' + Integer.toString(priority) + '>' + _ident + ": " + message; + + byte buf[] = msg.getBytes(); + DatagramPacket p = new DatagramPacket(buf, buf.length, _host, _port); + _socket.send(p); + } + catch(java.io.IOException ex) + { + Ice.SocketException se = new Ice.SocketException(); + se.initCause(ex); + throw se; + } + } + + private String _ident; + private DatagramSocket _socket; + private InetAddress _host; + private static int _port = 514; + + // + // Syslog facilities facilities (as defined in syslog.h) + // + private final int LOG_USER = 1; + + // + // Syslog priorities (as defined in syslog.h) + // + private final int LOG_ERR = 3; + private final int LOG_WARNING = 4; + private final int LOG_INFO = 6; +} + |