From 5fcd19eae6dad060b6bf73cde67273d0f2eed02f Mon Sep 17 00:00:00 2001 From: David Bariod Date: Sat, 27 Oct 2018 15:19:06 +0200 Subject: [PATCH] add a SetReportCaller on Logger object --- exported.go | 4 +--- logger.go | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/exported.go b/exported.go index 979582d..7342613 100644 --- a/exported.go +++ b/exported.go @@ -27,9 +27,7 @@ func SetFormatter(formatter Formatter) { // SetReportCaller sets whether the standard logger will include the calling // method as a field. func SetReportCaller(include bool) { - std.mu.Lock() - defer std.mu.Unlock() - std.ReportCaller = include + std.SetReportCaller(include) } // SetLevel sets the standard logger level. diff --git a/logger.go b/logger.go index 68fca98..5ceca0e 100644 --- a/logger.go +++ b/logger.go @@ -399,6 +399,12 @@ func (logger *Logger) SetOutput(output io.Writer) { logger.Out = output } +func (logger *Logger) SetReportCaller(reportCaller bool) { + logger.mu.Lock() + defer logger.mu.Unlock() + logger.ReportCaller = reportCaller +} + // ReplaceHooks replaces the logger hooks and returns the old ones func (logger *Logger) ReplaceHooks(hooks LevelHooks) LevelHooks { logger.mu.Lock()