From 6ad9bc4e9796c4a31d1ec5aa0a734c8eeedaa048 Mon Sep 17 00:00:00 2001 From: Unafilliate Code Date: Thu, 28 Nov 2024 16:52:25 -0500 Subject: [PATCH] Exposed Lock functionality/controls When implementers are managing multiple applications within a single service, multiple logrus instances are used. These services can have different subset configurations such as Minimum level assignment. --- logger.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/logger.go b/logger.go index 5ff0aef..cc81637 100644 --- a/logger.go +++ b/logger.go @@ -68,6 +68,10 @@ func (mw *MutexWrap) Unlock() { } } +func (mw *MutexWrap) Enable() { + mw.disabled = false +} + func (mw *MutexWrap) Disable() { mw.disabled = true } @@ -346,6 +350,18 @@ func (logger *Logger) Exit(code int) { } logger.ExitFunc(code) } +func (logger *Logger) Lock() { + logger.mu.Lock() +} +func (logger *Logger) Unlock() { + logger.mu.Unlock() +} + +// When an implementer is manipulating the logger concurrently, the +// implementer should call `SetYesLock` to enable the locking mechanism +func (logger *Logger) SetYesLock() { + logger.mu.Enable() +} //When file is opened with appending mode, it's safe to //write concurrently to a file (within 4k message on Linux).