From a4c73cf6c5a19c111cdac4d9d472d1f2287fa36c Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 2 Jan 2019 15:39:47 +1030 Subject: [PATCH] av: updated logging to suit changes made on iot and utils --- cmd/revid-cli/main.go | 72 ++++++++++---------- revid/cmd/h264-file-to-flv-rtmp/main.go | 4 +- revid/cmd/h264-file-to-mpgets-file/main.go | 4 +- revid/config.go | 34 +++++----- revid/revid.go | 78 +++++++++++----------- revid/senders.go | 18 ++--- 6 files changed, 105 insertions(+), 105 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 3fda0862..68d5c791 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -38,7 +38,8 @@ import ( "bitbucket.org/ausocean/av/revid" "bitbucket.org/ausocean/iot/pi/netsender" - "bitbucket.org/ausocean/utils/smartlogger" + "bitbucket.org/ausocean/iot/pi/smartlogger" + "bitbucket.org/ausocean/utils/logger" ) const ( @@ -46,7 +47,7 @@ const ( progName = "revid-cli" // Logging is set to INFO level. - defaultLogVerbosity = smartlogger.Debug + defaultLogVerbosity = logger.Debug ) // Other misc consts @@ -62,7 +63,7 @@ const ( var canProfile = true // The logger that will be used throughout -var logger *smartlogger.Logger +var log *logger.Logger func main() { useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?") @@ -74,7 +75,7 @@ func main() { // run revid for the specified duration rv, _, err := startRevid(nil, cfg) if err != nil { - cfg.Logger.Log(smartlogger.Fatal, pkg+"failed to start revid", err.Error()) + cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", err.Error()) } time.Sleep(*runDurationPtr) stopRevid(rv) @@ -83,7 +84,7 @@ func main() { err := run(nil, cfg) if err != nil { - logger.Log(smartlogger.Fatal, pkg+"failed to run revid", "error", err.Error()) + log.Log(logger.Fatal, pkg+"failed to run revid", "error", err.Error()) os.Exit(1) } } @@ -117,28 +118,27 @@ func handleFlags() revid.Config { intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") verticalFlipPtr = flag.Bool("VerticalFlip", false, "Flip video vertically: Yes, No") horizontalFlipPtr = flag.Bool("HorizontalFlip", false, "Flip video horizontally: Yes, No") - logPathPtr = flag.String("LogPath", defaultLogPath, "Path for logging files (default is /var/log/netsender/)") rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: : (port is generally 6970-6999)") ) flag.Parse() - logger = smartlogger.New(defaultLogVerbosity, *logPathPtr) + log = logger.New(defaultLogVerbosity, &smartlogger.New("/var/log/netsender").LogRoller) - cfg.Logger = logger + cfg.Logger = log if *cpuprofile != "" { if canProfile { f, err := os.Create(*cpuprofile) if err != nil { - logger.Log(smartlogger.Fatal, pkg+"could not create CPU profile", "error", err.Error()) + log.Log(logger.Fatal, pkg+"could not create CPU profile", "error", err.Error()) } if err := pprof.StartCPUProfile(f); err != nil { - logger.Log(smartlogger.Fatal, pkg+"could not start CPU profile", "error", err.Error()) + log.Log(logger.Fatal, pkg+"could not start CPU profile", "error", err.Error()) } defer pprof.StopCPUProfile() } else { - logger.Log(smartlogger.Warning, pkg+"ignoring cpuprofile flag - http/pprof built in.") + log.Log(logger.Warning, pkg+"ignoring cpuprofile flag - http/pprof built in.") } } @@ -149,7 +149,7 @@ func handleFlags() revid.Config { cfg.Input = revid.File case "": default: - logger.Log(smartlogger.Error, pkg+"bad input argument") + log.Log(logger.Error, pkg+"bad input argument") } switch *inputCodecPtr { @@ -157,7 +157,7 @@ func handleFlags() revid.Config { cfg.InputCodec = revid.H264 case "": default: - logger.Log(smartlogger.Error, pkg+"bad input codec argument") + log.Log(logger.Error, pkg+"bad input codec argument") } switch *output1Ptr { @@ -175,7 +175,7 @@ func handleFlags() revid.Config { cfg.Output1 = revid.Rtp case "": default: - logger.Log(smartlogger.Error, pkg+"bad output 1 argument") + log.Log(logger.Error, pkg+"bad output 1 argument") } switch *output2Ptr { @@ -193,7 +193,7 @@ func handleFlags() revid.Config { cfg.Output2 = revid.Rtp case "": default: - logger.Log(smartlogger.Error, pkg+"bad output 2 argument") + log.Log(logger.Error, pkg+"bad output 2 argument") } switch *rtmpMethodPtr { @@ -203,7 +203,7 @@ func handleFlags() revid.Config { cfg.RtmpMethod = revid.LibRtmp case "": default: - logger.Log(smartlogger.Error, pkg+"bad rtmp method argument") + log.Log(logger.Error, pkg+"bad rtmp method argument") } switch *packetizationPtr { @@ -215,18 +215,18 @@ func handleFlags() revid.Config { cfg.Packetization = revid.Flv case "": default: - logger.Log(smartlogger.Error, pkg+"bad packetization argument") + log.Log(logger.Error, pkg+"bad packetization argument") } switch *verbosityPtr { case "No": - cfg.LogLevel = smartlogger.Fatal + cfg.LogLevel = logger.Fatal case "Debug": - cfg.LogLevel = smartlogger.Debug - //logger.SetLevel(smartlogger.Debug) + cfg.LogLevel = logger.Debug + //logger.SetLevel(logger.Debug) case "": default: - logger.Log(smartlogger.Error, pkg+"bad verbosity argument") + log.Log(logger.Error, pkg+"bad verbosity argument") } cfg.Quantize = *quantizePtr @@ -252,10 +252,10 @@ func handleFlags() revid.Config { func run(rv *revid.Revid, cfg revid.Config) error { // initialize NetSender and use NetSender's logger //config.Logger = netsender.Logger() - logger.Log(smartlogger.Info, pkg+"running in NetSender mode") + log.Log(logger.Info, pkg+"running in NetSender mode") var ns netsender.Sender - err := ns.Init(logger, nil, nil, nil) + err := ns.Init(log, nil, nil, nil) if err != nil { return err } @@ -274,7 +274,7 @@ func run(rv *revid.Revid, cfg revid.Config) error { for { if err := send(&ns, rv); err != nil { - logger.Log(smartlogger.Error, pkg+"polling failed", "error", err.Error()) + log.Log(logger.Error, pkg+"polling failed", "error", err.Error()) time.Sleep(netSendRetryTime) continue } @@ -283,14 +283,14 @@ func run(rv *revid.Revid, cfg revid.Config) error { // vars changed vars, err := ns.Vars() if err != nil { - logger.Log(smartlogger.Error, pkg+"netSender failed to get vars", "error", err.Error()) + log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error()) time.Sleep(netSendRetryTime) continue } vs = ns.VarSum() if vars["mode"] == "Paused" { if !paused { - logger.Log(smartlogger.Info, pkg+"pausing revid") + log.Log(logger.Info, pkg+"pausing revid") stopRevid(rv) paused = true } @@ -369,13 +369,13 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "FfmpegRtmp": cfg.Output1 = revid.FfmpegRtmp default: - logger.Log(smartlogger.Warning, pkg+"invalid Output1 param", "value", value) + log.Log(logger.Warning, pkg+"invalid Output1 param", "value", value) continue } case "FramesPerClip": f, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid framesperclip param", "value", value) + log.Log(logger.Warning, pkg+"invalid framesperclip param", "value", value) break } cfg.FramesPerClip = uint(f) @@ -384,7 +384,7 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "Bitrate": r, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid framerate param", "value", value) + log.Log(logger.Warning, pkg+"invalid framerate param", "value", value) break } cfg.Bitrate = uint(r) @@ -395,21 +395,21 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "Height": h, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid height param", "value", value) + log.Log(logger.Warning, pkg+"invalid height param", "value", value) break } cfg.Height = uint(h) case "Width": w, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid width param", "value", value) + log.Log(logger.Warning, pkg+"invalid width param", "value", value) break } cfg.Width = uint(w) case "FrameRate": r, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid framerate param", "value", value) + log.Log(logger.Warning, pkg+"invalid framerate param", "value", value) break } cfg.FrameRate = uint(r) @@ -418,14 +418,14 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "Quantization": q, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid quantization param", "value", value) + log.Log(logger.Warning, pkg+"invalid quantization param", "value", value) break } cfg.Quantization = uint(q) case "IntraRefreshPeriod": p, err := strconv.ParseUint(value, 10, 0) if err != nil { - logger.Log(smartlogger.Warning, pkg+"invalid intrarefreshperiod param", "value", value) + log.Log(logger.Warning, pkg+"invalid intrarefreshperiod param", "value", value) break } cfg.IntraRefreshPeriod = uint(p) @@ -436,7 +436,7 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "false": cfg.FlipHorizontal = false default: - logger.Log(smartlogger.Warning, pkg+"invalid HorizontalFlip param", "value", value) + log.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value) } case "VerticalFlip": switch strings.ToLower(value) { @@ -445,7 +445,7 @@ func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars m case "false": cfg.FlipVertical = false default: - logger.Log(smartlogger.Warning, pkg+"invalid VerticalFlip param", "value", value) + log.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value) } default: } diff --git a/revid/cmd/h264-file-to-flv-rtmp/main.go b/revid/cmd/h264-file-to-flv-rtmp/main.go index 907e414b..5eba1e4e 100644 --- a/revid/cmd/h264-file-to-flv-rtmp/main.go +++ b/revid/cmd/h264-file-to-flv-rtmp/main.go @@ -61,11 +61,11 @@ func main() { RtmpMethod: revid.LibRtmp, RtmpUrl: *rtmpUrlPtr, Packetization: revid.Flv, - Logger: smartlogger.New(smartlogger.Info, logPath), + Logger: smartlogger.New(logger.Info, logPath), } revidInst, err := revid.New(config, nil) if err != nil { - config.Logger.Log(smartlogger.Error, "Should not have got an error!: ", err.Error()) + config.log.Log(logger.Error, "Should not have got an error!: ", err.Error()) return } revidInst.Start() diff --git a/revid/cmd/h264-file-to-mpgets-file/main.go b/revid/cmd/h264-file-to-mpgets-file/main.go index 5530f6c4..218940ab 100644 --- a/revid/cmd/h264-file-to-mpgets-file/main.go +++ b/revid/cmd/h264-file-to-mpgets-file/main.go @@ -52,11 +52,11 @@ func main() { Output1: revid.File, OutputFileName: outputFile, Packetization: revid.Mpegts, - Logger: smartlogger.New(smartlogger.Info, logPath), + Logger: smartlogger.New(logger.Info, logPath), } revidInst, err := revid.New(config, nil) if err != nil { - config.Logger.Log(smartlogger.Error, "Should not have got an error!:", err.Error()) + config.log.Log(logger.Error, "Should not have got an error!:", err.Error()) return } revidInst.Start() diff --git a/revid/config.go b/revid/config.go index 8becc91b..5f98de65 100644 --- a/revid/config.go +++ b/revid/config.go @@ -30,7 +30,7 @@ package revid import ( "errors" - "bitbucket.org/ausocean/utils/smartlogger" + "bitbucket.org/ausocean/utils/logger" ) // Config provides parameters relevant to a revid instance. A new config must @@ -124,7 +124,7 @@ func (c *Config) Validate(r *Revid) error { case No: case NothingDefined: c.LogLevel = defaultVerbosity - c.Logger.Log(smartlogger.Warning, pkg+"no LogLevel mode defined, defaulting", + c.Logger.Log(logger.Warning, pkg+"no LogLevel mode defined, defaulting", "LogLevel", defaultVerbosity) default: return errors.New("bad LogLevel defined in config") @@ -134,7 +134,7 @@ func (c *Config) Validate(r *Revid) error { case Raspivid: case File: case NothingDefined: - c.Logger.Log(smartlogger.Warning, pkg+"no input type defined, defaulting", "input", + c.Logger.Log(logger.Warning, pkg+"no input type defined, defaulting", "input", defaultInput) c.Input = defaultInput default: @@ -161,10 +161,10 @@ func (c *Config) Validate(r *Revid) error { } case NothingDefined: - c.Logger.Log(smartlogger.Warning, pkg+"no input codec defined, defaulting", + c.Logger.Log(logger.Warning, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec) c.InputCodec = defaultInputCodec - c.Logger.Log(smartlogger.Warning, pkg+"defaulting quantization", "quantization", + c.Logger.Log(logger.Warning, pkg+"defaulting quantization", "quantization", defaultQuantization) c.Quantization = defaultQuantization @@ -177,20 +177,20 @@ func (c *Config) Validate(r *Revid) error { case Udp: case Rtmp, FfmpegRtmp: if c.RtmpUrl == "" { - c.Logger.Log(smartlogger.Info, pkg+"no RTMP URL: falling back to HTTP") + c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP") c.Output1 = Http break } - c.Logger.Log(smartlogger.Info, pkg+"defaulting frames per clip for rtmp out", + c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out", "framesPerClip", defaultFramesPerClip) c.FramesPerClip = defaultFramesPerClip case NothingDefined: - c.Logger.Log(smartlogger.Warning, pkg+"no output defined, defaulting", "output", + c.Logger.Log(logger.Warning, pkg+"no output defined, defaulting", "output", defaultOutput) c.Output1 = defaultOutput fallthrough case Http, Rtp: - c.Logger.Log(smartlogger.Info, pkg+"defaulting frames per clip for http out", + c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", "framesPerClip", httpFramesPerClip) c.FramesPerClip = httpFramesPerClip default: @@ -203,7 +203,7 @@ func (c *Config) Validate(r *Revid) error { case Udp: case Rtmp, FfmpegRtmp: if c.RtmpUrl == "" { - c.Logger.Log(smartlogger.Info, pkg+"no RTMP URL: falling back to HTTP") + c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP") c.Output2 = Http break } @@ -214,38 +214,38 @@ func (c *Config) Validate(r *Revid) error { } if c.FramesPerClip < 1 { - c.Logger.Log(smartlogger.Warning, pkg+"no FramesPerClip defined, defaulting", + c.Logger.Log(logger.Warning, pkg+"no FramesPerClip defined, defaulting", "framesPerClip", defaultFramesPerClip) c.FramesPerClip = defaultFramesPerClip } if c.Width == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no width defined, defaulting", "width", defaultWidth) + c.Logger.Log(logger.Warning, pkg+"no width defined, defaulting", "width", defaultWidth) c.Width = defaultWidth } if c.Height == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no height defined, defaulting", "height", defaultHeight) + c.Logger.Log(logger.Warning, pkg+"no height defined, defaulting", "height", defaultHeight) c.Height = defaultHeight } if c.FrameRate == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no frame rate defined, defaulting", "fps", defaultFrameRate) + c.Logger.Log(logger.Warning, pkg+"no frame rate defined, defaulting", "fps", defaultFrameRate) c.FrameRate = defaultFrameRate } if c.Bitrate == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate) + c.Logger.Log(logger.Warning, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate) c.Bitrate = defaultBitrate } if c.IntraRefreshPeriod == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no intra refresh defined, defaulting", "intraRefresh", defaultIntraRefreshPeriod) + c.Logger.Log(logger.Warning, pkg+"no intra refresh defined, defaulting", "intraRefresh", defaultIntraRefreshPeriod) c.IntraRefreshPeriod = defaultIntraRefreshPeriod } if c.Quantization == 0 { - c.Logger.Log(smartlogger.Warning, pkg+"no quantization defined, defaulting", "quantization", defaultQuantization) + c.Logger.Log(logger.Warning, pkg+"no quantization defined, defaulting", "quantization", defaultQuantization) c.Quantization = defaultQuantization } else if c.Quantization > 51 { return errors.New("quantisation is over threshold") diff --git a/revid/revid.go b/revid/revid.go index 9e9efbd1..d509c6bb 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -44,8 +44,8 @@ import ( "bitbucket.org/ausocean/av/stream/lex" "bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/iot/pi/netsender" + "bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/ring" - "bitbucket.org/ausocean/utils/smartlogger" ) // Misc constants @@ -143,16 +143,16 @@ type packer struct { // write may include a dropped frame. func (p *packer) Write(frame []byte) (int, error) { if len(frame) > ringBufferElementSize { - p.owner.config.Logger.Log(smartlogger.Warning, pkg+"frame was too big", "frame size", len(frame)) + p.owner.config.Logger.Log(logger.Warning, pkg+"frame was too big", "frame size", len(frame)) return len(frame), nil } n, err := p.owner.buffer.Write(frame) if err != nil { if err == ring.ErrDropped { - p.owner.config.Logger.Log(smartlogger.Warning, pkg+"dropped frame", "frame size", len(frame)) + p.owner.config.Logger.Log(logger.Warning, pkg+"dropped frame", "frame size", len(frame)) return len(frame), nil } - p.owner.config.Logger.Log(smartlogger.Error, pkg+"unexpected ring buffer write error", "error", err.Error()) + p.owner.config.Logger.Log(logger.Error, pkg+"unexpected ring buffer write error", "error", err.Error()) return n, err } p.packetCount++ @@ -263,10 +263,10 @@ func (r *Revid) reset(config Config) error { } switch r.config.InputCodec { case H264: - r.config.Logger.Log(smartlogger.Info, pkg+"using H264 lexer") + r.config.Logger.Log(logger.Info, pkg+"using H264 lexer") r.lexTo = lex.H264 case Mjpeg: - r.config.Logger.Log(smartlogger.Info, pkg+"using MJPEG lexer") + r.config.Logger.Log(logger.Info, pkg+"using MJPEG lexer") r.lexTo = lex.MJPEG } @@ -288,10 +288,10 @@ func (r *Revid) reset(config Config) error { } r.encoder = stream.NopEncoder(&r.packer) case Mpegts: - r.config.Logger.Log(smartlogger.Info, pkg+"using MPEGTS packetisation") + r.config.Logger.Log(logger.Info, pkg+"using MPEGTS packetisation") r.encoder = mts.NewEncoder(&r.packer, float64(r.config.FrameRate)) case Flv: - r.config.Logger.Log(smartlogger.Info, pkg+"using FLV packetisation") + r.config.Logger.Log(logger.Info, pkg+"using FLV packetisation") r.encoder, err = flv.NewEncoder(&r.packer, true, true, int(r.config.FrameRate)) if err != nil { return err @@ -310,29 +310,29 @@ func (r *Revid) IsRunning() bool { // and packetising (if theres packetization) to a defined output. func (r *Revid) Start() { if r.isRunning { - r.config.Logger.Log(smartlogger.Warning, pkg+"revid.Start() called but revid already running") + r.config.Logger.Log(logger.Warning, pkg+"revid.Start() called but revid already running") return } - r.config.Logger.Log(smartlogger.Info, pkg+"starting Revid") - r.config.Logger.Log(smartlogger.Debug, pkg+"setting up output") + r.config.Logger.Log(logger.Info, pkg+"starting Revid") + r.config.Logger.Log(logger.Debug, pkg+"setting up output") r.isRunning = true - r.config.Logger.Log(smartlogger.Info, pkg+"starting output routine") + r.config.Logger.Log(logger.Info, pkg+"starting output routine") go r.outputClips() - r.config.Logger.Log(smartlogger.Info, pkg+"setting up input and receiving content") + r.config.Logger.Log(logger.Info, pkg+"setting up input and receiving content") go r.setupInput() } // Stop halts any processing of video data from a camera or file func (r *Revid) Stop() { if !r.isRunning { - r.config.Logger.Log(smartlogger.Warning, pkg+"revid.Stop() called but revid not running") + r.config.Logger.Log(logger.Warning, pkg+"revid.Stop() called but revid not running") return } - r.config.Logger.Log(smartlogger.Info, pkg+"stopping revid") + r.config.Logger.Log(logger.Info, pkg+"stopping revid") r.isRunning = false - r.config.Logger.Log(smartlogger.Info, pkg+"killing input proccess") + r.config.Logger.Log(logger.Info, pkg+"killing input proccess") // If a cmd process is running, we kill! if r.cmd != nil && r.cmd.Process != nil { r.cmd.Process.Kill() @@ -352,53 +352,53 @@ loop: case nil: // Do nothing. case ring.ErrTimeout: - r.config.Logger.Log(smartlogger.Warning, pkg+"ring buffer read timeout") + r.config.Logger.Log(logger.Warning, pkg+"ring buffer read timeout") continue default: - r.config.Logger.Log(smartlogger.Error, pkg+"unexpected error", "error", err.Error()) + r.config.Logger.Log(logger.Error, pkg+"unexpected error", "error", err.Error()) fallthrough case io.EOF: break loop } count += chunk.Len() - r.config.Logger.Log(smartlogger.Debug, pkg+"about to send") + r.config.Logger.Log(logger.Debug, pkg+"about to send") for i, dest := range r.destination { err = dest.load(chunk) if err != nil { - r.config.Logger.Log(smartlogger.Error, pkg+"failed to load clip to output"+strconv.Itoa(i)) + r.config.Logger.Log(logger.Error, pkg+"failed to load clip to output"+strconv.Itoa(i)) } } for i, dest := range r.destination { err = dest.send() if err == nil { - r.config.Logger.Log(smartlogger.Debug, pkg+"sent clip to output "+strconv.Itoa(i)) + r.config.Logger.Log(logger.Debug, pkg+"sent clip to output "+strconv.Itoa(i)) } else if r.config.SendRetry == false { - r.config.Logger.Log(smartlogger.Warning, pkg+"send to output "+strconv.Itoa(i)+"failed", "error", err.Error()) + r.config.Logger.Log(logger.Warning, pkg+"send to output "+strconv.Itoa(i)+"failed", "error", err.Error()) } else { - r.config.Logger.Log(smartlogger.Error, pkg+"send to output "+strconv.Itoa(i)+ + r.config.Logger.Log(logger.Error, pkg+"send to output "+strconv.Itoa(i)+ "failed, trying again", "error", err.Error()) err = dest.send() if err != nil && chunk.Len() > 11 { - r.config.Logger.Log(smartlogger.Error, pkg+"second send attempted failed, restarting connection", "error", err.Error()) + r.config.Logger.Log(logger.Error, pkg+"second send attempted failed, restarting connection", "error", err.Error()) for err != nil { time.Sleep(sendFailedDelay) if rs, ok := dest.(restarter); ok { - r.config.Logger.Log(smartlogger.Debug, pkg+"restarting session", "session", rs) + r.config.Logger.Log(logger.Debug, pkg+"restarting session", "session", rs) err = rs.restart() if err != nil { - r.config.Logger.Log(smartlogger.Error, pkg+"failed to restart rtmp session", "error", err.Error()) + r.config.Logger.Log(logger.Error, pkg+"failed to restart rtmp session", "error", err.Error()) r.isRunning = false return } - r.config.Logger.Log(smartlogger.Info, pkg+"restarted rtmp session") + r.config.Logger.Log(logger.Info, pkg+"restarted rtmp session") } err = dest.send() if err != nil { - r.config.Logger.Log(smartlogger.Error, pkg+"send failed again, with error", "error", err.Error()) + r.config.Logger.Log(logger.Error, pkg+"send failed again, with error", "error", err.Error()) } } } @@ -409,7 +409,7 @@ loop: for _, dest := range r.destination { dest.release() } - r.config.Logger.Log(smartlogger.Debug, pkg+"done reading that clip from ring buffer") + r.config.Logger.Log(logger.Debug, pkg+"done reading that clip from ring buffer") // Log some information regarding bitrate and ring buffer size if it's time now := time.Now() @@ -417,17 +417,17 @@ loop: if deltaTime > bitrateTime { // FIXME(kortschak): For subsecond deltaTime, this will give infinite bitrate. r.bitrate = int(float64(count*8) / float64(deltaTime/time.Second)) - r.config.Logger.Log(smartlogger.Debug, pkg+"bitrate (bits/s)", "bitrate", r.bitrate) - r.config.Logger.Log(smartlogger.Debug, pkg+"ring buffer size", "value", r.buffer.Len()) + r.config.Logger.Log(logger.Debug, pkg+"bitrate (bits/s)", "bitrate", r.bitrate) + r.config.Logger.Log(logger.Debug, pkg+"ring buffer size", "value", r.buffer.Len()) lastTime = now count = 0 } } - r.config.Logger.Log(smartlogger.Info, pkg+"not outputting clips anymore") + r.config.Logger.Log(logger.Info, pkg+"not outputting clips anymore") for i, dest := range r.destination { err := dest.close() if err != nil { - r.config.Logger.Log(smartlogger.Error, pkg+"failed to close output"+strconv.Itoa(i)+" destination", "error", err.Error()) + r.config.Logger.Log(logger.Error, pkg+"failed to close output"+strconv.Itoa(i)+" destination", "error", err.Error()) } } } @@ -435,7 +435,7 @@ loop: // startRaspivid sets up things for input from raspivid i.e. starts // a raspivid process and pipes it's data output. func (r *Revid) startRaspivid() error { - r.config.Logger.Log(smartlogger.Info, pkg+"starting raspivid") + r.config.Logger.Log(logger.Info, pkg+"starting raspivid") const disabled = "0" args := []string{ @@ -468,7 +468,7 @@ func (r *Revid) startRaspivid() error { case Mjpeg: args = append(args, "--codec", "MJPEG") } - r.config.Logger.Log(smartlogger.Info, pkg+"raspivid args", "raspividArgs", strings.Join(args, " ")) + r.config.Logger.Log(logger.Info, pkg+"raspivid args", "raspividArgs", strings.Join(args, " ")) r.cmd = exec.Command("raspivid", args...) stdout, err := r.cmd.StdoutPipe() @@ -477,13 +477,13 @@ func (r *Revid) startRaspivid() error { } err = r.cmd.Start() if err != nil { - r.config.Logger.Log(smartlogger.Fatal, pkg+"cannot start raspivid", "error", err.Error()) + r.config.Logger.Log(logger.Fatal, pkg+"cannot start raspivid", "error", err.Error()) } - r.config.Logger.Log(smartlogger.Info, pkg+"reading camera data") + r.config.Logger.Log(logger.Info, pkg+"reading camera data") delay := time.Second / time.Duration(r.config.FrameRate) err = r.lexTo(r.encoder, stdout, delay) - r.config.Logger.Log(smartlogger.Info, pkg+"finished reading camera data") + r.config.Logger.Log(logger.Info, pkg+"finished reading camera data") return err } @@ -493,7 +493,7 @@ func (r *Revid) setupInputForFile() error { f, err := os.Open(r.config.InputFileName) if err != nil { - r.config.Logger.Log(smartlogger.Error, err.Error()) + r.config.Logger.Log(logger.Error, err.Error()) r.Stop() return err } diff --git a/revid/senders.go b/revid/senders.go index 6606350e..9c9abca1 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -39,8 +39,8 @@ import ( "bitbucket.org/ausocean/av/stream/mts" "bitbucket.org/ausocean/av/stream/rtp" "bitbucket.org/ausocean/iot/pi/netsender" + "bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/ring" - "bitbucket.org/ausocean/utils/smartlogger" ) // loadSender is a destination to send a *ring.Chunk to. @@ -166,18 +166,18 @@ func (s *httpSender) extractMeta(r string) error { // Extract time from reply t, err := dec.Int("ts") if err != nil { - s.log(smartlogger.Warning, pkg+"No timestamp in reply") + s.log(logger.Warning, pkg+"No timestamp in reply") } else { - s.log(smartlogger.Debug, fmt.Sprintf("%v got timestamp: %v", pkg, t)) + s.log(logger.Debug, fmt.Sprintf("%v got timestamp: %v", pkg, t)) mts.SetTimeStamp(uint64(t)) } // Extract location from reply g, err := dec.String("ll") if err != nil { - s.log(smartlogger.Warning, pkg+"No location in reply") + s.log(logger.Warning, pkg+"No location in reply") } else { - s.log(smartlogger.Debug, fmt.Sprintf("%v got location: %v", pkg, g)) + s.log(logger.Debug, fmt.Sprintf("%v got location: %v", pkg, g)) mts.SetLocation(g) } @@ -269,10 +269,10 @@ func newRtmpSender(url string, timeout uint, retries int, log func(lvl int8, msg if err == nil { break } - log(smartlogger.Error, err.Error()) + log(logger.Error, err.Error()) sess.Close() if n < retries-1 { - log(smartlogger.Info, pkg+"retry rtmp connection") + log(logger.Info, pkg+"retry rtmp connection") } } if err != nil { @@ -315,10 +315,10 @@ func (s *rtmpSender) restart() error { if err == nil { break } - s.log(smartlogger.Error, err.Error()) + s.log(logger.Error, err.Error()) s.sess.Close() if n < s.retries-1 { - s.log(smartlogger.Info, pkg+"retry rtmp connection") + s.log(logger.Info, pkg+"retry rtmp connection") } } return err