cmd/revid-cli: send logs using netlogger

This commit is contained in:
Scott 2020-01-20 10:32:22 +10:30
parent 39d0fa12d0
commit b1a7adc487
1 changed files with 17 additions and 6 deletions

View File

@ -32,7 +32,9 @@ package main
import ( import (
"flag" "flag"
"io"
"os" "os"
"path/filepath"
"runtime/pprof" "runtime/pprof"
"strconv" "strconv"
"strings" "strings"
@ -44,10 +46,11 @@ import (
"bitbucket.org/ausocean/av/device/raspivid" "bitbucket.org/ausocean/av/device/raspivid"
"bitbucket.org/ausocean/av/revid" "bitbucket.org/ausocean/av/revid"
"bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/av/revid/config"
"bitbucket.org/ausocean/iot/pi/netlogger"
"bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/iot/pi/netsender"
"bitbucket.org/ausocean/iot/pi/sds" "bitbucket.org/ausocean/iot/pi/sds"
"bitbucket.org/ausocean/iot/pi/smartlogger"
"bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/logger"
"gopkg.in/natefinch/lumberjack.v2"
) )
// Revid modes // Revid modes
@ -73,8 +76,8 @@ var canProfile = true
// The logger that will be used throughout. // The logger that will be used throughout.
var ( var (
smartLog *smartlogger.Smartlogger netLogger *netlogger.NetLogger
log *logger.Logger log *logger.Logger
) )
const ( const (
@ -163,8 +166,16 @@ func handleFlags() config.Config {
cfg.LogLevel = defaultLogVerbosity cfg.LogLevel = defaultLogVerbosity
} }
smartLog = smartlogger.New(*logPathPtr) netLogger = netlogger.New()
log = logger.New(cfg.LogLevel, &smartLog.LogRoller, true) log = logger.New(cfg.LogLevel, io.MultiWriter(
&lumberjack.Logger{
Filename: filepath.Join(*logPathPtr, "netsender.log"),
MaxSize: 500, // megabytes
MaxBackups: 10,
MaxAge: 28, // days
},
netLogger,
), true)
cfg.Logger = log cfg.Logger = log
@ -355,7 +366,7 @@ func run(cfg config.Config) {
ns.SetMode(paused, &vs) ns.SetMode(paused, &vs)
} }
smartLog.SendLogs(ns) netLogger.SendLogs(ns)
sleep: sleep:
sleepTime, err := strconv.Atoi(ns.Param("mp")) sleepTime, err := strconv.Atoi(ns.Param("mp"))