feat(logging): add interactive shell detection for console output

This commit is contained in:
Sergey Krashevich
2024-05-28 09:10:32 +03:00
parent 8e571a66e3
commit a79061c7c2
3 changed files with 19 additions and 1 deletions
+2 -1
View File
@@ -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())),
}
}