Skip to content
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

Logging interface #82

Merged
merged 3 commits into from
Feb 11, 2019
Merged

Logging interface #82

merged 3 commits into from
Feb 11, 2019

Conversation

muirdm
Copy link
Contributor

@muirdm muirdm commented Jan 31, 2019

Fixes #15.

Replace seelog with a custom logger interface. This change is backwards compatible except that the existing LogLevel and LogFormat config fields no longer have any effect. Users will have to reset their min log level if they weren't using the default of "info".

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Muir Manders added 2 commits January 31, 2019 13:51
The seelog logger had various drawbacks:
- not easily user configurable (e.g. can't disable, can't write to a
  file, can't write to stderr, can't write to json, etc)
- uses global seelog instance which can conflict w/ other packages
  or user's logger

The replacement logger uses a simple Logger interface:

type Logger interface {
	Log(level LogLevel, msg fmt.Stringer)
}

Rather than a separate method for each log level, the level is passed
as an argument. This makes it easy/possible to add more log levels in
the future. The lowest log level is now "debug" instead of seelog's
"trace" (seemed mildly confusing to have a log method named "trace" in
a cloud tracing package).

We use a fmt.Stringer so any log message serialization can be deferred
until the message is actually written.

There is a default Logger implementation the user can use via
NewDefaultLogger(io.Writer, LogLevel) to create a logger that writes
log messages of at least a certain log level to a specified io.Writer.

The logger defaults to a stdout writer of min level "info".

The "xraylog" package is the user visible logging API. It contains
"xray" in the package name so it doesn't annoyingly look like every
other "logger" package (e.g. to goimports). The user can set a new
logger using xray.SetLogger().

The actual logging instance and logging wrapper methods are in an
internal "logger" package hidden from the user. There are
Info(...interface{}) and Infof(string, ...interface{}) varieties for
each log level. In addition there is a DebugDeferred(func() string)
takes an arbitrary function (which won't get called unless the log
message is actually logged).
@muirdm
Copy link
Contributor Author

muirdm commented Feb 5, 2019

Hi - can someone work with me on this? I think it resolves all issues I know about with the logger.

@luluzhao
Copy link
Contributor

luluzhao commented Feb 5, 2019

Hi @muirrn, I am looking at it right now and will you let you about my feedback ASAP.

xraylog/xray_log.go Outdated Show resolved Hide resolved
awsplugins/beanstalk/beanstalk.go Show resolved Hide resolved
internal/logger/logger.go Show resolved Hide resolved
README.md Show resolved Hide resolved
@yogiraj07
Copy link
Contributor

Hi @muirrn , I am currently working on this PR. Will post an update soon.

@yogiraj07 yogiraj07 self-assigned this Feb 6, 2019
Use a mutex to synchronize calls to underling io.Writer. This avoids
log message interleaving and potentially worse race conditions,
depending on what the writer is.

Also tweak the invalid LogLevel String() to be UNKNOWNLOGLEVEL instead
of just UNKNOWN so it is easier to understand what is unknown if it
ever shows up.
@yogiraj07 yogiraj07 merged commit 852dc09 into aws:master Feb 11, 2019
@yogiraj07
Copy link
Contributor

Hi @muirrn ,
Thank you for working with me. I have merged the PR.

Best,
Yogi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants