From fc9bbf2f57995271c5cd6911ede7a2ebc5ea7c6f Mon Sep 17 00:00:00 2001 From: Daniel Bershatsky Date: Wed, 27 Jun 2018 20:29:28 +0300 Subject: [PATCH] [#241] Allow to set writer during logger usage. --- exported.go | 4 +--- logger.go | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/exported.go b/exported.go index 013183e..6c98afd 100644 --- a/exported.go +++ b/exported.go @@ -15,9 +15,7 @@ func StandardLogger() *Logger { // SetOutput sets the standard logger output. func SetOutput(out io.Writer) { - std.mu.Lock() - defer std.mu.Unlock() - std.Out = out + std.SetOutput(out) } // SetFormatter sets the standard logger formatter. diff --git a/logger.go b/logger.go index 0ac8ce2..0c1b05e 100644 --- a/logger.go +++ b/logger.go @@ -316,6 +316,12 @@ func (logger *Logger) SetLevel(level Level) { atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) } +func (logger *Logger) SetOutput(out io.Writer) { + logger.mu.Lock() + defer logger.mu.Unlock() + logger.Out = out +} + func (logger *Logger) AddHook(hook Hook) { logger.mu.Lock() defer logger.mu.Unlock()