From 0c03a05a0e896c23dcd631acafd2f35add6a3fec Mon Sep 17 00:00:00 2001 From: conor Date: Thu, 21 Dec 2017 14:04:49 -0500 Subject: [PATCH 1/3] mirror and wrap Logger instance methods in exported.go --- .gitignore | 1 + exported.go | 16 +++------------- logger.go | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 66be63a..c722487 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ logrus +.idea \ No newline at end of file diff --git a/exported.go b/exported.go index 013183e..141e951 100644 --- a/exported.go +++ b/exported.go @@ -15,36 +15,26 @@ 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. func SetFormatter(formatter Formatter) { - std.mu.Lock() - defer std.mu.Unlock() - std.Formatter = formatter + std.SetFormatter(formatter) } // SetLevel sets the standard logger level. func SetLevel(level Level) { - std.mu.Lock() - defer std.mu.Unlock() std.SetLevel(level) } // GetLevel returns the standard logger level. func GetLevel() Level { - std.mu.Lock() - defer std.mu.Unlock() - return std.level() + return std.GetLevel() } // AddHook adds a hook to the standard logger hooks. func AddHook(hook Hook) { - std.mu.Lock() - defer std.mu.Unlock() std.Hooks.Add(hook) } diff --git a/logger.go b/logger.go index fdaf8a6..91617fc 100644 --- a/logger.go +++ b/logger.go @@ -312,12 +312,33 @@ func (logger *Logger) level() Level { return Level(atomic.LoadUint32((*uint32)(&logger.Level))) } +// SetLevel sets the logger level. func (logger *Logger) SetLevel(level Level) { atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) } +// GetLevel returns the logger level. +func (logger *Logger) GetLevel() Level { + return logger.level() +} + +// AddHook adds a hook to the logger hooks. func (logger *Logger) AddHook(hook Hook) { logger.mu.Lock() defer logger.mu.Unlock() logger.Hooks.Add(hook) } + +// SetFormatter sets the logger formatter. +func (logger *Logger) SetFormatter(formatter Formatter) { + logger.mu.Lock() + defer logger.mu.Unlock() + logger.Formatter = formatter +} + +// SetOutput sets the logger output. +func (logger *Logger) SetOutput(output io.Writer) { + logger.mu.Lock() + defer logger.mu.Unlock() + logger.Out = output +} From 20cc8e2bc33863de7191b9bfb55d27804e05e90e Mon Sep 17 00:00:00 2001 From: conor Date: Thu, 21 Dec 2017 14:10:48 -0500 Subject: [PATCH 2/3] remove .gitignore changes --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c722487..bb7e111 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -logrus -.idea \ No newline at end of file +logrus \ No newline at end of file From eb156905d7c48f0f2191a3f805e59849c9c018ed Mon Sep 17 00:00:00 2001 From: conor Date: Thu, 21 Dec 2017 14:16:49 -0500 Subject: [PATCH 3/3] remove .gitignore changes and update AddHook --- .gitignore | 2 +- exported.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bb7e111..66be63a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -logrus \ No newline at end of file +logrus diff --git a/exported.go b/exported.go index 141e951..e5e484f 100644 --- a/exported.go +++ b/exported.go @@ -35,7 +35,7 @@ func GetLevel() Level { // AddHook adds a hook to the standard logger hooks. func AddHook(hook Hook) { - std.Hooks.Add(hook) + std.AddHook(hook) } // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.