Breaking change to logger interface, remove Log prefix.
This commit is contained in:
+3
-3
@@ -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.
|
||||
|
||||
+3
-3
@@ -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...))
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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...))
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user