From 5d4c6780a1515ced1521aa80a5cf1cc6434ec39a Mon Sep 17 00:00:00 2001 From: Piyush Singariya Date: Tue, 1 Feb 2022 10:45:35 +0530 Subject: [PATCH] adding output option for logger for golang testing in mesheryctl Signed-off-by: Piyush Singariya --- logger/logger.go | 5 ++++- logger/types.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/logger/logger.go b/logger/logger.go index effa2668..d92d394c 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -54,8 +54,11 @@ func New(appname string, opts Options) (Handler, error) { // log.SetReportCaller(true) log.SetOutput(os.Stdout) - log.SetLevel(logrus.InfoLevel) + if opts.Output != nil { + log.SetOutput(opts.Output) + } + log.SetLevel(logrus.InfoLevel) if opts.DebugLevel { log.SetLevel(logrus.DebugLevel) } diff --git a/logger/types.go b/logger/types.go index 5ba50dce..1f9b6726 100644 --- a/logger/types.go +++ b/logger/types.go @@ -1,5 +1,7 @@ package logger +import "io" + const ( JsonLogFormat = iota SyslogLogFormat @@ -11,4 +13,5 @@ type Format int type Options struct { Format Format DebugLevel bool + Output io.Writer }