From 7601e01fc136d44396646795374c86eec2c04e42 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 2 Jul 2022 17:53:41 -0400 Subject: [PATCH] Add an extra token to each line of stderr from termshark processes For example: time="2022-07-02T12:46:22-04:00" level=error msg="tshark: Configuration Profile \"test1\" does not exist" cmd=/home/gcla/bin/tshark This might make it a little easier to understand when a tshark process fails to run correctly. I may go further and capture stderr for display in a UI error dialog. --- pcap/cmds.go | 2 +- utils.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pcap/cmds.go b/pcap/cmds.go index c82c33f..f1116f9 100644 --- a/pcap/cmds.go +++ b/pcap/cmds.go @@ -46,7 +46,7 @@ func (c *Command) String() string { func (c *Command) Start() error { c.Lock() defer c.Unlock() - c.Cmd.Stderr = log.StandardLogger().Writer() + c.Cmd.Stderr = termshark.ErrLogger("cmd", c.Path) c.PutInNewGroupOnUnix() res := c.Cmd.Start() return res diff --git a/utils.go b/utils.go index f07ffe0..58bbe37 100644 --- a/utils.go +++ b/utils.go @@ -674,6 +674,13 @@ func SaveOffsetToConfig(name string, offsets2 []resizable.Offset) { //====================================================================== +func ErrLogger(key string, val string) *io.PipeWriter { + l := log.StandardLogger() + return log.NewEntry(l).WithField(key, val).WriterLevel(log.ErrorLevel) +} + +//====================================================================== + // Need to publish fields for template use type JumpPos struct { Summary string `json:"summary"`