From d8ebc7a2a98ff661eb74e0620a1afd637943cc54 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Sat, 31 Jan 2015 12:39:53 +0700 Subject: [PATCH] change comments with example --- daemon.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/daemon.go b/daemon.go index a815a6e..5dfbe04 100644 --- a/daemon.go +++ b/daemon.go @@ -12,7 +12,7 @@ In the current implementation is only supported Linux and Mac Os X daemon. Example: - //Example of the daemon with echo service + // Example of a daemon with echo service package main import ( @@ -36,6 +36,8 @@ Example: port = ":9977" ) + var stdlog, errlog *log.Logger + // Service has embedded daemon type Service struct { daemon.Daemon @@ -90,8 +92,8 @@ Example: 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 @@ -126,16 +128,21 @@ Example: } } + 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)