aboutsummaryrefslogtreecommitdiff
path: root/logger/logger.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-14 16:05:55 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-14 16:05:55 +0200
commit1b29f7dafc233ed893d8f35e5edbb0c2e357d55d (patch)
tree731b6f6560ea149da3d6512a4bc757480add761e /logger/logger.go
parent33967236e18c33d0d83b34b76f8238c3d588b21d (diff)
downloaddna-backup-1b29f7dafc233ed893d8f35e5edbb0c2e357d55d.tar.gz
dna-backup-1b29f7dafc233ed893d8f35e5edbb0c2e357d55d.zip
logger add SetOutput + basic tests
Diffstat (limited to 'logger/logger.go')
-rw-r--r--logger/logger.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/logger/logger.go b/logger/logger.go
index bb76657..9cd4b33 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -3,6 +3,7 @@ package logger
import (
"fmt"
+ "io"
"log"
"os"
"runtime/debug"
@@ -13,6 +14,7 @@ type severity int
type logger interface {
Output(calldepth int, s string) error
+ SetOutput(w io.Writer)
SetFlags(flag int)
}
@@ -103,6 +105,13 @@ func (l *Logger) output(s severity, depth int, txt string) {
l.loggers[s].Output(3+depth, txt+"\033[0m")
}
+// SetOutput changes the output of the logger.
+func (l *Logger) SetOutput(w io.Writer) {
+ for _, logger := range l.loggers {
+ logger.SetOutput(w)
+ }
+}
+
// SetFlags sets the output flags for the logger.
func (l *Logger) SetFlags(flag int) {
for _, logger := range l.loggers {
@@ -194,6 +203,11 @@ func (l *Logger) Fatalf(format string, v ...interface{}) {
os.Exit(1)
}
+// SetOutput changes the output of the default logger.
+func SetOutput(w io.Writer) {
+ defaultLogger.SetOutput(w)
+}
+
// SetFlags sets the output flags for the logger.
func SetFlags(flag int) {
defaultLogger.SetFlags(flag)