add zap for default logger

This commit is contained in:
zhiqiang feng
2020-12-28 11:06:36 +08:00
parent f43412b235
commit 2cbfbdbbca
9 changed files with 81 additions and 45 deletions
+7 -10
View File
@@ -16,8 +16,6 @@ limitations under the License.
package cmd
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
@@ -70,8 +68,7 @@ func start() {
// and then notify the program that it can finish.
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
l.Info(sig)
utils.ServerRunning = false
utils.StopSocketServer()
done <- true
@@ -80,27 +77,27 @@ func start() {
// The program will wait here until it gets the
// expected signal (as indicated by the goroutine
// above sending a value on `done`) and then exit.
fmt.Println("awaiting signal")
l.Info("awaiting signal")
_ = utils.InitDb(dbFile, dbInit)
go utils.Listen(socketAddress)
for utils.ServerRunning {
if !utils.IsPortOpen() {
log.Println("try to open port")
l.Info("try to open port")
err := utils.OpenPort(device, baudrate, bytesize, stopbits)
if err != nil {
log.Fatal("error in open serial port ", err)
l.Fatal("error in open serial port ", err)
}
log.Println("starting read")
l.Info("starting read")
}
buffer, count := utils.ReadPort()
if count > 0 {
if lograw {
log.Print(string(buffer))
l.Error(string(buffer))
}
utils.Append(buffer)
}
}
<-done
fmt.Println("exiting")
l.Info("exiting")
}