Terminal logging is now coloured only on an interactive terminal
The terminal logger always coloured its text, so output piped or redirected to a file, and the systemd journal, got escape codes. It now colours only an interactive terminal. The service's logs can therefore go to the journal: logging.file is now optional for it, and the unit's comments and the README say so.
This commit is contained in:
1 parent
2aeb2993b0
commit
71eca2f194
4 files changed
+45
-9
No files matched your search
@@ -79,16 +79,20 @@ func Shutdown() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// LogToTerminal sends all logging to stdout as coloured text, replacing the
|
||||
// default slog logger. When stdout is an interactive terminal, loggers
|
||||
// derived from it report so to WritesToTerminal.
|
||||
// LogToTerminal sends all logging to stdout as text, replacing the default
|
||||
// slog logger. The text is coloured only on an interactive terminal, so a
|
||||
// pipe, a file or the systemd journal gets no escape codes. On an
|
||||
// interactive terminal, loggers derived from it report so to
|
||||
// WritesToTerminal.
|
||||
func LogToTerminal() {
|
||||
interactive := isTerminal(terminal)
|
||||
opts := &tint.Options{
|
||||
Level: &logLevel,
|
||||
TimeFormat: "*",
|
||||
NoColor: !interactive,
|
||||
}
|
||||
handler := tint.NewTextHandler(terminal, opts)
|
||||
if isTerminal(terminal) {
|
||||
if interactive {
|
||||
handler = terminalHandler{
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user