add zap logger

This commit is contained in:
zhiqiang feng
2020-12-28 15:58:00 +08:00
parent c06ec0a519
commit 0619229ec5
10 changed files with 82 additions and 49 deletions
+9 -7
View File
@@ -16,10 +16,12 @@ limitations under the License.
package cmd
import (
"fmt"
"os"
"os/signal"
"syscall"
"fmt"
"go.uber.org/zap"
"it2000.com.cn/tele-recv/utils"
"github.com/spf13/cobra"
@@ -68,7 +70,7 @@ func start() {
// and then notify the program that it can finish.
go func() {
sig := <-sigs
l.Info(sig)
logger.Info("got ", zap.Any("signal", sig))
utils.ServerRunning = false
utils.StopSocketServer()
done <- true
@@ -77,17 +79,17 @@ 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.
l.Info("awaiting signal")
logger.Info("awaiting signal")
_ = utils.InitDb(dbFile, dbInit)
go utils.Listen(socketAddress)
for utils.ServerRunning {
if !utils.IsPortOpen() {
l.Info("try to open port")
logger.Info("try to open port")
err := utils.OpenPort(device, baudrate, bytesize, stopbits)
if err != nil {
l.Fatal("error in open serial port ", err)
logger.Fatal("error in open serial port ", zap.Error(err))
}
l.Info("starting read")
logger.Info("starting read")
}
buffer, count := utils.ReadPort()
if count > 0 {
@@ -98,6 +100,6 @@ func start() {
}
}
<-done
l.Info("exiting")
logger.Info("exiting")
}