log/syslog: Solaris portability patches.

From-SVN: r194566
This commit is contained in:
Ian Lance Taylor 2012-12-17 21:07:27 +00:00
parent a48bd7c6a5
commit a57bf4070a

View File

@ -10,7 +10,9 @@ package syslog
import (
"fmt"
"os"
"syscall"
"time"
)
func unixSyslog() (conn serverConn, err error) {
@ -21,14 +23,17 @@ 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) writeString(p Priority, hostname, tag, msg string) (int, error) {
timestamp := time.Now().Format(time.RFC3339)
log := fmt.Sprintf("%s %s %s[%d]: %s", timestamp, hostname, tag, os.Getpid(), msg)
buf, err := syscall.BytePtrFromString(log)
if err != nil {
return 0, err
}
syscall.Entersyscall()
syslog_c(int(p), buf)
syscall.Exitsyscall()
return len(msg), nil
}
func (libcConn) close() error {