import (
"fmt"
+ "os"
"syscall"
+ "time"
)
func unixSyslog() (conn serverConn, err error) {
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 {