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

Refactor logging and expose ability to toggle level in running process #195

Merged
merged 8 commits into from
Oct 31, 2017

Conversation

zwass
Copy link
Contributor

@zwass zwass commented Oct 25, 2017

  • Create a new logger that defaults to info level logging.
  • Add the ability to toggle info/debug logging by sending SIGUSR2.
  • Refactor some logging.

@@ -26,7 +26,6 @@ func parseUUID() grpctransport.ServerOption {

func NewGRPCServer(endpoints KolideClient, logger log.Logger) pb.ApiServer {
options := []grpctransport.ServerOption{
grpctransport.ServerErrorLogger(logger),
Copy link
Contributor Author

@zwass zwass Oct 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I killed this because the docs say

ServerErrorLogger is used to log non-terminal errors. By default, no errors are logged.

and I think we should leave it at the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree. This method is for server side implementations so it would not affect the launcher client. Is there a reason we wouldn't want to log if a grpc error happened (unable to decode, request failed etc)

IMO if you're removing it, the NewGRPCServer should accept a list of grpctransport.ServerOption because there's no way to add a logger if it's needed.

log/log.go Outdated
}

func NewLogger(w io.Writer) Logger {
base := log.NewJSONLogger(log.NewSyncWriter(w))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often prefer logfmt for reading logs locally. This hardcodes the output format too.

Copy link
Contributor

@groob groob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, although I'm still skeptical about requiring the custom logger interface for the helper methods.

grpctransport "github.com/go-kit/kit/transport/grpc"
"github.com/kolide/launcher/log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for servers. since the log.Logger in this file has changed to a much larger interface, any NewGRPCServer will require to instantiate a new launcher/log.Logger rather than the go-kit one. I'm not sure that's a good change.

@@ -25,7 +25,7 @@ type logmw struct {
func (mw logmw) RequestEnrollment(ctx context.Context, enrollSecret, hostIdentifier string) (errcode string, reauth bool, err error) {
defer func(begin time.Time) {
uuid, _ := uuid.FromContext(ctx)
mw.logger.Log(
mw.logger.Debug(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These logging middleware are also used by the server and should not be enforcing a level. The level was enforced when the logger is created.

See the pull request that removed Debug for more info #181

log/log.go Outdated
AllowInfo()
}

type logger struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be possible to scale this package back in this way?

  • Export the logger struct.
  • Return the struct.
  • Don't declare an interface in this package.
  • Only make any necessary changes in main, leaving other packages to only consume a go-kit logger?

The reason I'm asking is because the logger is now required by all the packages in this repo, including ones meant to be imported by server-side implementations.

I wouldn't be opposed to discussing/iterating on the proposed interface here, but I think it should be more carefully considered before it propagates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, for GCP servers I have created this helper https://github.com/kolide/kit/blob/566c8f56a6ff7daba204818fbab0f2cb854b3310/logutil/logutil.go#L22 to rewrite the level key. I'm not sure how that will work with this logger.

@zwass
Copy link
Contributor Author

zwass commented Oct 31, 2017

@groob I scoped this back in line with your comments and I feel better about it. Please let me know what you think.

@groob
Copy link
Contributor

groob commented Oct 31, 2017

🚢

@zwass zwass merged commit 274c7d6 into kolide:master Oct 31, 2017
@zwass zwass deleted the refactor_logging branch October 31, 2017 23:36
groob added a commit to groob/kit-1 that referenced this pull request Jan 19, 2018
groob added a commit to groob/kit-1 that referenced this pull request Jan 19, 2018
groob added a commit to kolide/kit that referenced this pull request Jan 19, 2018
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.

2 participants