1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
--- helpers/service/simple.go.orig 2021-07-20 11:41:09 UTC
+++ helpers/service/simple.go
@@ -6,6 +6,8 @@ import (
"os/signal"
"syscall"
+ "fmt"
+ "log/syslog"
"github.com/kardianos/service"
)
@@ -25,6 +27,39 @@ type SimpleService struct {
c *service.Config
}
+// Begin copy from /vendor/github.com/ayufan/golang-kardianos-service/service_unix.go
+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...)))
+}
+// End copy
+
// Run should be called shortly after the program entry point.
// After Interface.Stop has finished running, Run will stop blocking.
// After Run stops blocking, the program must exit shortly after.
@@ -86,7 +121,13 @@ func (s *SimpleService) Logger(errs chan<- error) (ser
// SystemLogger opens and returns a system logger. If errs is non-nil errors
// will be sent on errs as well as returned from Logger's functions.
func (s *SimpleService) SystemLogger(errs chan<- error) (service.Logger, error) {
- return nil, ErrNotSupported
+ // Begin copy from vendor/github.com/ayufan/golang-kardianos-service/service_unix.go
+ w, err := syslog.New(syslog.LOG_INFO, s.c.Name)
+ if err != nil {
+ return nil, err
+ }
+ return sysLogger{w, errs}, nil
+ // End copy
}
// String displays the name of the service. The display name if present,
|