log/syslog: Solaris portability patches.
[official-gcc.git] / libgo / go / log / syslog / syslog_libc.go
blob2d14d5d20a88207263adae3798060835a4048773
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // gccgo specific implementation of syslog for Solaris. Solaris uses
6 // STREAMS to communicate with syslogd. That is enough of a pain that
7 // we just call the libc function.
9 package syslog
11 import (
12 "fmt"
13 "os"
14 "syscall"
15 "time"
18 func unixSyslog() (conn serverConn, err error) {
19 return libcConn(0), nil
22 type libcConn int
24 func syslog_c(int, *byte)
26 func (libcConn) writeString(p Priority, hostname, tag, msg string) (int, error) {
27 timestamp := time.Now().Format(time.RFC3339)
28 log := fmt.Sprintf("%s %s %s[%d]: %s", timestamp, hostname, tag, os.Getpid(), msg)
29 buf, err := syscall.BytePtrFromString(log)
30 if err != nil {
31 return 0, err
33 syscall.Entersyscall()
34 syslog_c(int(p), buf)
35 syscall.Exitsyscall()
36 return len(msg), nil
39 func (libcConn) close() error {
40 return nil