From a589360f7d1e030e50855e21a69cf29108548dcd Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Sat, 31 Jan 2015 12:35:30 +0700 Subject: [PATCH] extend example with logger --- example/myservice.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/example/myservice.go b/example/myservice.go index cc371bd..6b58241 100644 --- a/example/myservice.go +++ b/example/myservice.go @@ -22,6 +22,8 @@ const ( port = ":9977" ) +var stdlog, errlog *log.Logger + // Service has embedded daemon type Service struct { daemon.Daemon @@ -76,8 +78,8 @@ func (service *Service) Manage() (string, error) { case conn := <-listen: go handleClient(conn) case killSignal := <-interrupt: - log.Println("Got signal:", killSignal) - log.Println("Stoping listening on ", listener.Addr()) + stdlog.Println("Got signal:", killSignal) + stdlog.Println("Stoping listening on ", listener.Addr()) listener.Close() if killSignal == os.Interrupt { return "Daemon was interruped by system signal", nil @@ -112,16 +114,21 @@ func handleClient(client net.Conn) { } } +func init() { + stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime) + errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime) +} + func main() { srv, err := daemon.New(name, description) if err != nil { - fmt.Println("Error: ", err) + errlog.Println("Error: ", err) os.Exit(1) } service := &Service{srv} status, err := service.Manage() if err != nil { - fmt.Println(status, "\nError: ", err) + errlog.Println(status, "\nError: ", err) os.Exit(1) } fmt.Println(status)