-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arun Gopalpuri
committed
Dec 8, 2020
1 parent
1910d85
commit 2b30b94
Showing
5 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package logger | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
var ( | ||
_globalMU sync.RWMutex | ||
_globalL Logger | ||
) | ||
|
||
// ReplaceGlobals replaces the global Logger and returns a | ||
// function to restore the original values. It's safe for concurrent use. | ||
func ReplaceGlobals(logger Logger) func() { | ||
_globalMU.Lock() | ||
prev := _globalL | ||
_globalL = logger | ||
_globalMU.Unlock() | ||
return func() { ReplaceGlobals(prev) } | ||
} | ||
|
||
// L returns the global Logger, which can be reconfigured with ReplaceGlobals. | ||
// It's safe for concurrent use. | ||
func L() Logger { | ||
_globalMU.RLock() | ||
l := _globalL | ||
_globalMU.RUnlock() | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters