You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
To check the log level, I had to read the source code to know if DebugLevel is greater or lesser than InfoLevel.
So it can be intersting to have some
IsXxxxxEnabled
methods on
exported
,
logger
en
entry
like:
logger.IsDebugEnabled()
logger.IsInfoEnabled()
logger.IsWarnEnabled()
logger.IsErrorEnabled()
logger.IsFatalEnabled()
logger.IsPanicEnabled()
Also, to respect the DRY pattern, I suggest to replace duplicated
if logger.level() >= DebugLevel
by these new methods. So if the business definition of "Debug is enabled" changes, we'll have to change it only once.
Adding 6 methods on 'exported', 'logger' and 'entry':
- IsDebugEnabled() bool
- IsInfoEnabled() bool
- IsWarnEnabled() bool
- IsErrorEnabled() bool
- IsFatalEnabled() bool
- IsPanicEnabled() bool
Replace duplicated 'if logger.level() >= XxxxLevel' by a call to the new methods in 'logger' and 'entry'
Closes sirupsen#761
Adding 6 methods on 'exported', 'logger' and 'entry':
- IsDebugEnabled() bool
- IsInfoEnabled() bool
- IsWarnEnabled() bool
- IsErrorEnabled() bool
- IsFatalEnabled() bool
- IsPanicEnabled() bool
Replace duplicated 'if logger.level() >= XxxxLevel' by a call to the new methods in 'logger' and 'entry'
Closes sirupsen#761
I don't realy understand your concerne (or I maybe missunderstand what you wanna mean).
If the function is reduced to only
return logger.level() >= DebugLevel
, the golang compiler will inline it. So there will be no strings passed by copy as argument.
Furthermore, if we take the
IsDebugEnabled()
as an example, this one will be:
func (logger *Logger) IsDebugEnabled() bool {
return logger.level() >= DebugLevel
So there will be no argument to pass.
My comments are in regard to your general request. I’m adding another benefit.
Log.Debug(“hello, world”) will create a copy of the string in order to cast the string to an interface. If the debug is not allowed, the cost to create is still paid.
I’m on my phone, so the code is more pseudo. The idea is sound.
If Log.IsDebugEnabled() {
Log.Debug(“hello, world”)
Incurse only the cost of the check, no other stack or heap variable creation.
Oh okay, so I just missunderstood your comment... My bad ;)
You're right, it's another benefit.
Thanks for your support.
Adding 6 methods on 'exported', 'logger' and 'entry':
- IsDebugEnabled() bool
- IsInfoEnabled() bool
- IsWarnEnabled() bool
- IsErrorEnabled() bool
- IsFatalEnabled() bool
- IsPanicEnabled() bool
Replace duplicated 'if logger.level() >= XxxxLevel' by a call to the new methods in 'logger' and 'entry'
Closes sirupsen#761