feat(logging): add interactive shell detection for console output
This commit is contained in:
+2
-1
@@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/shell"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -15,7 +16,7 @@ func NewLogger(format string, level string) zerolog.Logger {
|
||||
|
||||
if format != "json" {
|
||||
writer = zerolog.ConsoleWriter{
|
||||
Out: writer, TimeFormat: "15:04:05.000", NoColor: format == "text",
|
||||
Out: writer, TimeFormat: "15:04:05.000", NoColor: (format == "text" || !shell.IsInteractive(os.Stdout.Fd())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !unix
|
||||
|
||||
package shell
|
||||
|
||||
func IsInteractive(fd uintptr) bool {
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//go:build unix
|
||||
|
||||
package shell
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func IsInteractive(fd uintptr) bool {
|
||||
_, err := unix.IoctlGetTermios(int(fd), unix.TIOCGETA)
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user