aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/syslog
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-07 01:11:29 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-07 01:11:29 +0000
commit9c63abc9a1d127f95162756467284cf76b47aff8 (patch)
tree84f27a6ab44d932e4b0455f18390b070b4de626e /libgo/go/syslog
parent374280238f934fa851273e2ee16ba53be890c6b8 (diff)
downloadgcc-9c63abc9a1d127f95162756467284cf76b47aff8.zip
gcc-9c63abc9a1d127f95162756467284cf76b47aff8.tar.gz
gcc-9c63abc9a1d127f95162756467284cf76b47aff8.tar.bz2
libgo: Update to weekly 2011-11-09.
From-SVN: r182073
Diffstat (limited to 'libgo/go/syslog')
-rw-r--r--libgo/go/syslog/syslog.go149
-rw-r--r--libgo/go/syslog/syslog_c.c19
-rw-r--r--libgo/go/syslog/syslog_libc.go36
-rw-r--r--libgo/go/syslog/syslog_test.go113
-rw-r--r--libgo/go/syslog/syslog_unix.go31
5 files changed, 0 insertions, 348 deletions
diff --git a/libgo/go/syslog/syslog.go b/libgo/go/syslog/syslog.go
deleted file mode 100644
index 26a2f73..0000000
--- a/libgo/go/syslog/syslog.go
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package syslog provides a simple interface to the system log service. It
-// can send messages to the syslog daemon using UNIX domain sockets, UDP, or
-// TCP connections.
-package syslog
-
-import (
- "fmt"
- "log"
- "net"
- "os"
-)
-
-type Priority int
-
-const (
- // From /usr/include/sys/syslog.h.
- // These are the same on Linux, BSD, and OS X.
- LOG_EMERG Priority = iota
- LOG_ALERT
- LOG_CRIT
- LOG_ERR
- LOG_WARNING
- LOG_NOTICE
- LOG_INFO
- LOG_DEBUG
-)
-
-// A Writer is a connection to a syslog server.
-type Writer struct {
- priority Priority
- prefix string
- conn serverConn
-}
-
-type serverConn interface {
- writeBytes(p Priority, prefix string, b []byte) (int, error)
- writeString(p Priority, prefix string, s string) (int, error)
- close() error
-}
-
-type netConn struct {
- conn net.Conn
-}
-
-// New establishes a new connection to the system log daemon.
-// Each write to the returned writer sends a log message with
-// the given priority and prefix.
-func New(priority Priority, prefix string) (w *Writer, err error) {
- return Dial("", "", priority, prefix)
-}
-
-// Dial establishes a connection to a log daemon by connecting
-// to address raddr on the network net.
-// Each write to the returned writer sends a log message with
-// the given priority and prefix.
-func Dial(network, raddr string, priority Priority, prefix string) (w *Writer, err error) {
- if prefix == "" {
- prefix = os.Args[0]
- }
- var conn serverConn
- if network == "" {
- conn, err = unixSyslog()
- } else {
- var c net.Conn
- c, err = net.Dial(network, raddr)
- conn = netConn{c}
- }
- return &Writer{priority, prefix, conn}, err
-}
-
-// Write sends a log message to the syslog daemon.
-func (w *Writer) Write(b []byte) (int, error) {
- if w.priority > LOG_DEBUG || w.priority < LOG_EMERG {
- return 0, os.EINVAL
- }
- return w.conn.writeBytes(w.priority, w.prefix, b)
-}
-
-func (w *Writer) writeString(p Priority, s string) (int, error) {
- return w.conn.writeString(p, w.prefix, s)
-}
-
-func (w *Writer) Close() error { return w.conn.close() }
-
-// Emerg logs a message using the LOG_EMERG priority.
-func (w *Writer) Emerg(m string) (err error) {
- _, err = w.writeString(LOG_EMERG, m)
- return err
-}
-// Crit logs a message using the LOG_CRIT priority.
-func (w *Writer) Crit(m string) (err error) {
- _, err = w.writeString(LOG_CRIT, m)
- return err
-}
-// ERR logs a message using the LOG_ERR priority.
-func (w *Writer) Err(m string) (err error) {
- _, err = w.writeString(LOG_ERR, m)
- return err
-}
-
-// Warning logs a message using the LOG_WARNING priority.
-func (w *Writer) Warning(m string) (err error) {
- _, err = w.writeString(LOG_WARNING, m)
- return err
-}
-
-// Notice logs a message using the LOG_NOTICE priority.
-func (w *Writer) Notice(m string) (err error) {
- _, err = w.writeString(LOG_NOTICE, m)
- return err
-}
-// Info logs a message using the LOG_INFO priority.
-func (w *Writer) Info(m string) (err error) {
- _, err = w.writeString(LOG_INFO, m)
- return err
-}
-// Debug logs a message using the LOG_DEBUG priority.
-func (w *Writer) Debug(m string) (err error) {
- _, err = w.writeString(LOG_DEBUG, m)
- return err
-}
-
-func (n netConn) writeBytes(p Priority, prefix string, b []byte) (int, error) {
- return fmt.Fprintf(n.conn, "<%d>%s: %s\n", p, prefix, b)
-}
-
-func (n netConn) writeString(p Priority, prefix string, s string) (int, error) {
- return fmt.Fprintf(n.conn, "<%d>%s: %s\n", p, prefix, s)
-}
-
-func (n netConn) close() error {
- return n.conn.Close()
-}
-
-// NewLogger provides an object that implements the full log.Logger interface,
-// but sends messages to Syslog instead; flag is passed as is to Logger;
-// priority will be used for all messages sent using this interface.
-// All messages are logged with priority p.
-func NewLogger(p Priority, flag int) *log.Logger {
- s, err := New(p, "")
- if err != nil {
- return nil
- }
- return log.New(s, "", flag)
-}
diff --git a/libgo/go/syslog/syslog_c.c b/libgo/go/syslog/syslog_c.c
deleted file mode 100644
index f49b9ff..0000000
--- a/libgo/go/syslog/syslog_c.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* syslog_c.c -- call syslog for Go.
-
- Copyright 2011 The Go Authors. All rights reserved.
- Use of this source code is governed by a BSD-style
- license that can be found in the LICENSE file. */
-
-#include <syslog.h>
-
-/* We need to use a C function to call the syslog function, because we
- can't represent a C varargs function in Go. */
-
-void syslog_c(int, const char*)
- asm ("libgo_syslog.syslog.syslog_c");
-
-void
-syslog_c (int priority, const char *msg)
-{
- syslog (priority, "%s", msg);
-}
diff --git a/libgo/go/syslog/syslog_libc.go b/libgo/go/syslog/syslog_libc.go
deleted file mode 100644
index fb98ad7..0000000
--- a/libgo/go/syslog/syslog_libc.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// gccgo specific implementation of syslog for Solaris. Solaris uses
-// STREAMS to communicate with syslogd. That is enough of a pain that
-// we just call the libc function.
-
-package syslog
-
-import (
- "fmt"
- "syscall"
-)
-
-func unixSyslog() (conn serverConn, err error) {
- return libcConn(0), nil
-}
-
-type libcConn int
-
-func syslog_c(int, *byte)
-
-func (libcConn) writeBytes(p Priority, prefix string, b []byte) (int, error) {
- syslog_c(int(p), syscall.StringBytePtr(fmt.Sprintf("%s: %s", prefix, b)))
- return len(b), nil
-}
-
-func (libcConn) writeString(p Priority, prefix string, s string) (int, error) {
- syslog_c(int(p), syscall.StringBytePtr(fmt.Sprintf("%s: %s", prefix, s)))
- return len(s), nil
-}
-
-func (libcConn) close() error {
- return nil
-}
diff --git a/libgo/go/syslog/syslog_test.go b/libgo/go/syslog/syslog_test.go
deleted file mode 100644
index 5c0b3e0..0000000
--- a/libgo/go/syslog/syslog_test.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-package syslog
-
-import (
- "io"
- "log"
- "net"
- "testing"
-)
-
-var serverAddr string
-
-func runSyslog(c net.PacketConn, done chan<- string) {
- var buf [4096]byte
- var rcvd string = ""
- for {
- n, _, err := c.ReadFrom(buf[0:])
- if err != nil || n == 0 {
- break
- }
- rcvd += string(buf[0:n])
- }
- done <- rcvd
-}
-
-func startServer(done chan<- string) {
- c, e := net.ListenPacket("udp", "127.0.0.1:0")
- if e != nil {
- log.Fatalf("net.ListenPacket failed udp :0 %v", e)
- }
- serverAddr = c.LocalAddr().String()
- c.SetReadTimeout(100e6) // 100ms
- go runSyslog(c, done)
-}
-
-func skipNetTest(t *testing.T) bool {
- if testing.Short() {
- // Depends on syslog daemon running, and sometimes it's not.
- t.Logf("skipping syslog test during -short")
- return true
- }
- return false
-}
-
-func TestNew(t *testing.T) {
- if skipNetTest(t) {
- return
- }
- s, err := New(LOG_INFO, "")
- if err != nil {
- t.Fatalf("New() failed: %s", err)
- }
- // Don't send any messages.
- s.Close()
-}
-
-func TestNewLogger(t *testing.T) {
- if skipNetTest(t) {
- return
- }
- f := NewLogger(LOG_INFO, 0)
- if f == nil {
- t.Error("NewLogger() failed")
- }
-}
-
-func TestDial(t *testing.T) {
- if skipNetTest(t) {
- return
- }
- l, err := Dial("", "", LOG_ERR, "syslog_test")
- if err != nil {
- t.Fatalf("Dial() failed: %s", err)
- }
- l.Close()
-}
-
-func TestUDPDial(t *testing.T) {
- done := make(chan string)
- startServer(done)
- l, err := Dial("udp", serverAddr, LOG_INFO, "syslog_test")
- if err != nil {
- t.Fatalf("syslog.Dial() failed: %s", err)
- }
- msg := "udp test"
- l.Info(msg)
- expected := "<6>syslog_test: udp test\n"
- rcvd := <-done
- if rcvd != expected {
- t.Fatalf("s.Info() = '%q', but wanted '%q'", rcvd, expected)
- }
-}
-
-func TestWrite(t *testing.T) {
- done := make(chan string)
- startServer(done)
- l, err := Dial("udp", serverAddr, LOG_ERR, "syslog_test")
- if err != nil {
- t.Fatalf("syslog.Dial() failed: %s", err)
- }
- msg := "write test"
- _, err = io.WriteString(l, msg)
- if err != nil {
- t.Fatalf("WriteString() failed: %s", err)
- }
- expected := "<3>syslog_test: write test\n"
- rcvd := <-done
- if rcvd != expected {
- t.Fatalf("s.Info() = '%q', but wanted '%q'", rcvd, expected)
- }
-}
diff --git a/libgo/go/syslog/syslog_unix.go b/libgo/go/syslog/syslog_unix.go
deleted file mode 100644
index b1c929a..0000000
--- a/libgo/go/syslog/syslog_unix.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package syslog
-
-import (
- "errors"
- "net"
-)
-
-// unixSyslog opens a connection to the syslog daemon running on the
-// local machine using a Unix domain socket.
-
-func unixSyslog() (conn serverConn, err error) {
- logTypes := []string{"unixgram", "unix"}
- logPaths := []string{"/dev/log", "/var/run/syslog"}
- var raddr string
- for _, network := range logTypes {
- for _, path := range logPaths {
- raddr = path
- conn, err := net.Dial(network, raddr)
- if err != nil {
- continue
- } else {
- return netConn{conn}, nil
- }
- }
- }
- return nil, errors.New("Unix syslog delivery error")
-}