diff --git a/service.go b/service.go index 077df55..5c58250 100644 --- a/service.go +++ b/service.go @@ -56,9 +56,9 @@ type Controller interface { // A service that implements ServiceLogger can perform simple system logging. type Logger interface { // Basic log functions in the context of the service. - LogError(format string, a ...interface{}) error - LogWarning(format string, a ...interface{}) error - LogInfo(format string, a ...interface{}) error + Error(format string, a ...interface{}) error + Warning(format string, a ...interface{}) error + Info(format string, a ...interface{}) error } // Depreciated. Use osext.Executable instead. diff --git a/service_darwin.go b/service_darwin.go index 6dc9937..6f0501f 100644 --- a/service_darwin.go +++ b/service_darwin.go @@ -105,13 +105,13 @@ func (s *darwinLaunchdService) Run(onStart, onStop func() error) error { return onStop() } -func (s *darwinLaunchdService) LogError(format string, a ...interface{}) error { +func (s *darwinLaunchdService) Error(format string, a ...interface{}) error { return s.logger.Err(fmt.Sprintf(format, a...)) } -func (s *darwinLaunchdService) LogWarning(format string, a ...interface{}) error { +func (s *darwinLaunchdService) Warning(format string, a ...interface{}) error { return s.logger.Warning(fmt.Sprintf(format, a...)) } -func (s *darwinLaunchdService) LogInfo(format string, a ...interface{}) error { +func (s *darwinLaunchdService) Info(format string, a ...interface{}) error { return s.logger.Info(fmt.Sprintf(format, a...)) } diff --git a/service_linux.go b/service_linux.go index d4d1ce4..6d74e7a 100644 --- a/service_linux.go +++ b/service_linux.go @@ -99,13 +99,13 @@ func (s *linuxUpstartService) Stop() error { return cmd.Run() } -func (s *linuxUpstartService) LogError(format string, a ...interface{}) error { +func (s *linuxUpstartService) Error(format string, a ...interface{}) error { return s.logger.Err(fmt.Sprintf(format, a...)) } -func (s *linuxUpstartService) LogWarning(format string, a ...interface{}) error { +func (s *linuxUpstartService) Warning(format string, a ...interface{}) error { return s.logger.Warning(fmt.Sprintf(format, a...)) } -func (s *linuxUpstartService) LogInfo(format string, a ...interface{}) error { +func (s *linuxUpstartService) Info(format string, a ...interface{}) error { return s.logger.Info(fmt.Sprintf(format, a...)) } diff --git a/service_windows.go b/service_windows.go index 77716dc..5c88c5a 100644 --- a/service_windows.go +++ b/service_windows.go @@ -153,19 +153,19 @@ func (ws *windowsService) Stop() error { return err } -func (ws *windowsService) LogError(format string, a ...interface{}) error { +func (ws *windowsService) Error(format string, a ...interface{}) error { if ws.logger == nil { return nil } return ws.logger.Error(3, fmt.Sprintf(format, a...)) } -func (ws *windowsService) LogWarning(format string, a ...interface{}) error { +func (ws *windowsService) Warning(format string, a ...interface{}) error { if ws.logger == nil { return nil } return ws.logger.Warning(2, fmt.Sprintf(format, a...)) } -func (ws *windowsService) LogInfo(format string, a ...interface{}) error { +func (ws *windowsService) Info(format string, a ...interface{}) error { if ws.logger == nil { return nil } diff --git a/stdservice/console_log.go b/stdservice/console_log.go index 185a2b0..1cb0ec2 100644 --- a/stdservice/console_log.go +++ b/stdservice/console_log.go @@ -4,15 +4,15 @@ import "fmt" type ConsoleLogger struct{} -func (ConsoleLogger) LogError(format string, a ...interface{}) error { +func (ConsoleLogger) Error(format string, a ...interface{}) error { fmt.Printf("E: "+format, a...) return nil } -func (ConsoleLogger) LogWarning(format string, a ...interface{}) error { +func (ConsoleLogger) Warning(format string, a ...interface{}) error { fmt.Printf("W: "+format, a...) return nil } -func (ConsoleLogger) LogInfo(format string, a ...interface{}) error { +func (ConsoleLogger) Info(format string, a ...interface{}) error { fmt.Printf("I: "+format, a...) return nil } diff --git a/stdservice/stdservice.go b/stdservice/stdservice.go index b715fa2..29639a5 100644 --- a/stdservice/stdservice.go +++ b/stdservice/stdservice.go @@ -14,11 +14,11 @@ type Config struct { // Called when the service starts or stops. // Stop() may be nil. - Start, Stop func() + Start, Stop func(c *Config) // Called after logging may be setup but before the service is started. // Init() is optional and may be nil. - Init func() + Init func(c *Config) s service.Service l service.Logger @@ -69,10 +69,10 @@ func Run(c *Config) { c.l = ConsoleLogger{} defer func() { if c.Stop != nil { - c.Stop() + c.Stop(c) } }() - c.Start() + c.Start(c) case "start": err = s.Start() if err != nil { @@ -92,21 +92,21 @@ func Run(c *Config) { } if c.Init != nil { - c.Init() + c.Init(c) } err = s.Run(func() error { // start - go c.Start() + go c.Start(c) return nil }, func() error { // stop if c.Stop != nil { - c.Stop() + c.Stop(c) } return nil }) if err != nil { - c.l.LogError(err.Error()) + c.l.Error(err.Error()) } }