| 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. |
| 4 |
|
| 5 |
// +build solaris irix |
| 6 |
|
| 7 |
// gccgo specific implementation of syslog for Solaris. Solaris uses |
| 8 |
// STREAMS to communicate with syslogd. That is enough of a pain that |
| 9 |
// we just call the libc function. |
| 10 |
|
| 11 |
package syslog |
| 12 |
|
| 13 |
import ( |
| 14 |
"fmt" |
| 15 |
"os" |
| 16 |
"syscall" |
| 17 |
"time" |
| 18 |
) |
| 19 |
|
| 20 |
func unixSyslog() (conn serverConn, err error) { |
| 21 |
return libcConn(0), nil |
| 22 |
} |
| 23 |
|
| 24 |
type libcConn int |
| 25 |
|
| 26 |
func syslog_c(int, *byte) |
| 27 |
|
| 28 |
func (libcConn) writeString(p Priority, hostname, tag, msg, nl string) error { |
| 29 |
timestamp := time.Now().Format(time.RFC3339) |
| 30 |
log := fmt.Sprintf("%s %s %s[%d]: %s%s", timestamp, hostname, tag, os.Getpid(), msg, nl) |
| 31 |
buf, err := syscall.BytePtrFromString(log) |
| 32 |
if err != nil { |
| 33 |
return err |
| 34 |
} |
| 35 |
syscall.Entersyscall() |
| 36 |
syslog_c(int(p), buf) |
| 37 |
syscall.Exitsyscall() |
| 38 |
return nil |
| 39 |
} |
| 40 |
|
| 41 |
func (libcConn) close() error { |
| 42 |
return nil |
| 43 |
} |