mirror of
https://github.com/kardianos/service.git
synced 2025-10-01 07:02:31 +08:00
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2015 Daniel Theophanes.
|
|
// Use of this source code is governed by a zlib-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build linux darwin
|
|
|
|
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"log/syslog"
|
|
"os/exec"
|
|
)
|
|
|
|
func newSysLogger(name string, errs chan<- error) (Logger, error) {
|
|
w, err := syslog.New(syslog.LOG_INFO, name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return sysLogger{w, errs}, nil
|
|
}
|
|
|
|
type sysLogger struct {
|
|
*syslog.Writer
|
|
errs chan<- error
|
|
}
|
|
|
|
func (s sysLogger) send(err error) error {
|
|
if err != nil && s.errs != nil {
|
|
s.errs <- err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s sysLogger) Error(v ...interface{}) error {
|
|
return s.send(s.Writer.Err(fmt.Sprint(v...)))
|
|
}
|
|
func (s sysLogger) Warning(v ...interface{}) error {
|
|
return s.send(s.Writer.Warning(fmt.Sprint(v...)))
|
|
}
|
|
func (s sysLogger) Info(v ...interface{}) error {
|
|
return s.send(s.Writer.Info(fmt.Sprint(v...)))
|
|
}
|
|
func (s sysLogger) Errorf(format string, a ...interface{}) error {
|
|
return s.send(s.Writer.Err(fmt.Sprintf(format, a...)))
|
|
}
|
|
func (s sysLogger) Warningf(format string, a ...interface{}) error {
|
|
return s.send(s.Writer.Warning(fmt.Sprintf(format, a...)))
|
|
}
|
|
func (s sysLogger) Infof(format string, a ...interface{}) error {
|
|
return s.send(s.Writer.Info(fmt.Sprintf(format, a...)))
|
|
}
|
|
|
|
func run(command string, arguments ...string) error {
|
|
cmd := exec.Command(command, arguments...)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("%q failed: %v, %s", command, err, out)
|
|
}
|
|
return nil
|
|
}
|