Breaking change to logger interface, remove Log prefix.

This commit is contained in:
Daniel Theophanes
2013-03-02 22:38:31 -08:00
parent 83aba983e4
commit 663a6abbf9
6 changed files with 23 additions and 23 deletions
+3 -3
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
}
+3 -3
View File
@@ -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
}
+8 -8
View File
@@ -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())
}
}