-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
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
Add Core function to logp.Logger to allow access to backing zapcore.Core. #88
Conversation
@@ -224,6 +224,11 @@ func (l *Logger) Sync() error { | |||
return l.logger.Sync() | |||
} | |||
|
|||
// Core returns the backend zapcore.Core for the logger. | |||
func (l *Logger) Core() zapcore.Core { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be better to define a type alias like it's done with the zap.Option
:
elastic-agent-libs/logp/logger.go
Lines 27 to 28 in 89215ad
// LogOption configures a Logger. | |
type LogOption = zap.Option |
I don't know how far we want to go exposing the zap
types in our library. I see that the Logger
struct just has zap
types directly:
elastic-agent-libs/logp/logger.go
Lines 30 to 34 in 89215ad
// Logger logs messages to the configured output. | |
type Logger struct { | |
logger *zap.Logger | |
sugar *zap.SugaredLogger | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see a need to hide it. It is zap
and zapcore
under the hood and the go.mod for any project that imports elastic-agent-libs
will show zap
and zapcore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would rather an abstraction should we decide to switch from zap to something else. I guess that's the point. But I'm okay with this.
What does this PR do?
Adds the ability to retrieve the
zapcore.Core
from thelogp.Logger
. This allows the ability to write entries directly into the logger bypassing any log levels settings.Why is it important?
This is needed for the work on elastic/elastic-agent#221. The
io.Writer
connected tostdout
andstderr
from the spawned subprocesses will read the output from the process and output it directly to thezapcore.Core
. That is required because each component and unit can have its own log level different from the Elastic Agent log level. Because of that design it requires that log messages bypass the log level settings for the logger used by Elastic Agent.Checklist
[ ] I have added tests that prove my fix is effective or that my feature worksCHANGELOG.md
Related issues