From aaadf26b90b8088aec0997492d726472609cc85e Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 6 Dec 2023 09:17:52 +0100 Subject: [PATCH 1/2] separate writer for wwlog.Info Signed-off-by: Christian Goll --- CHANGELOG.md | 1 + internal/pkg/wwlog/wwlog.go | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db295d19..16b56677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,6 +125,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support importing containers with symlinked `/bin/sh` #797 - Don't panic on malformed passwd #527 - Update iPXE building script +- wwlog.Info|Recv|Send will go to stdout, rest to stderr ## [4.4.0] 2023-01-18 diff --git a/internal/pkg/wwlog/wwlog.go b/internal/pkg/wwlog/wwlog.go index 98f67f2a..e4d6d9e3 100644 --- a/internal/pkg/wwlog/wwlog.go +++ b/internal/pkg/wwlog/wwlog.go @@ -52,6 +52,7 @@ var ( levelNames = []string{"NOTSET"} logLevel = INFO logErr io.Writer = os.Stderr + logOut io.Writer = os.Stdout logFormatter LogFormatter = DefaultFormatter ) @@ -153,11 +154,30 @@ func GetLogLevel() int { Set the log output writer By default they are set to output writer */ -func SetLogWriter(err io.Writer) { - logErr = err +func SetLogWriter(newOut io.Writer) { + logErr = newOut + logOut = newOut } -func GetLogWriter() io.Writer { +/* +Set the log ofr info only +*/ +func SetLogWriterInfo(newOut io.Writer) { + logOut = newOut +} + +/* +Set the log ofr info only +*/ +func SetLogWriterErr(newOut io.Writer) { + logOut = newOut +} + +func GetLogWriterInfo() io.Writer { + return logOut +} + +func GetLogWriterErr() io.Writer { return logErr } @@ -196,8 +216,12 @@ func LogCaller(level int, skip int, err error, message string, a ...interface{}) } message = logFormatter(logLevel, &rec) + if level == INFO || level == RECV || level == SEND { + fmt.Fprint(logOut, message) + } else { + fmt.Fprint(logErr, message) - fmt.Fprint(logErr, message) + } } } From 5efaf6d9f5fe5ccf3b8ac3630d779abf87d8df3c Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 8 Dec 2023 10:09:48 +0100 Subject: [PATCH 2/2] added extra OUTPUT level Signed-off-by: Christian Goll --- CHANGELOG.md | 2 +- internal/pkg/wwlog/wwlog.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b56677..08461b73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,7 +125,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support importing containers with symlinked `/bin/sh` #797 - Don't panic on malformed passwd #527 - Update iPXE building script -- wwlog.Info|Recv|Send will go to stdout, rest to stderr +- Send Info, Recv, Send, and Out messages to stdout; and others to stderr ## [4.4.0] 2023-01-18 diff --git a/internal/pkg/wwlog/wwlog.go b/internal/pkg/wwlog/wwlog.go index e4d6d9e3..0b8ee5ca 100644 --- a/internal/pkg/wwlog/wwlog.go +++ b/internal/pkg/wwlog/wwlog.go @@ -36,9 +36,11 @@ var ( ERROR = SetLevelName(40, "ERROR") SECWARN = SetLevelName(31, "SECWARN") WARN = SetLevelName(30, "WARN") + ERROUT = SetLevelName(29, "ERROUT") SEND = SetLevelName(27, "SEND") RECV = SetLevelName(26, "RECV") SERV = SetLevelName(25, "SERV") + OUT = SetLevelName(22, "OUT") SECINFO = SetLevelName(21, "SECINFO") INFO = SetLevelName(20, "INFO") SECVERBOSE = SetLevelName(16, "SECVERBOSE") @@ -216,7 +218,7 @@ func LogCaller(level int, skip int, err error, message string, a ...interface{}) } message = logFormatter(logLevel, &rec) - if level == INFO || level == RECV || level == SEND { + if level == INFO || level == RECV || level == SEND || level == OUT { fmt.Fprint(logOut, message) } else { fmt.Fprint(logErr, message) @@ -273,6 +275,10 @@ func Info(message string, a ...interface{}) { LogCaller(INFO, 1, nil, message, a...) } +func Output(message string, a ...interface{}) { + LogCaller(OUT, 1, nil, message, a...) +} + func InfoExc(err error, message string, a ...interface{}) { LogCaller(INFO, 1, err, message, a...) } @@ -305,6 +311,10 @@ func SecWarn(message string, a ...interface{}) { LogCaller(SECWARN, 1, nil, message, a...) } +func ErrOut(message string, a ...interface{}) { + LogCaller(ERROUT, 1, nil, message, a...) +} + func Error(message string, a ...interface{}) { LogCaller(ERROR, 1, nil, message, a...) }