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

Remove host Logger() access in favor of ctx logger #260

Merged
merged 3 commits into from
Feb 17, 2017
Merged

Conversation

anuptalwalkar
Copy link
Contributor

No description provided.

@mention-bot
Copy link

@anuptalwalkar, thanks for your PR! By analyzing the history of the files in this pull request, we identified @shawnburke, @yutongp and @madhuravi to be potential reviewers.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 92.581% when pulling b69958d on with-logger into 0626e44 on master.

@ascandella
Copy link
Contributor

ascandella commented Feb 15, 2017 via email

@anuptalwalkar
Copy link
Contributor Author

Nothing to lose here. We add module name to the logger today, which is now passed and available in the Logger(ctx), other than that additional fields should come from zap logger which is initialized during service setup and accessed on ulog.Logger(ctx)

@@ -42,6 +41,7 @@ import (
"github.com/uber/jaeger-client-go/config"
)

<<<<<<< HEAD
Copy link

Choose a reason for hiding this comment

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

wat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rebasing/cleaning up

service/host.go Outdated
@@ -278,9 +278,9 @@ func (s *host) start() Control {

s.shutdownMu.Unlock()
if _, err := s.shutdown(e, "", nil); err != nil {
s.Logger().Error("Unable to shut down modules", "initialError", e, "shutdownError", err)
s.log.Error("Unable to shut down modules", "initialError", e, "shutdownError", err)
Copy link

Choose a reason for hiding this comment

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

Looks like instead of logging here, we should wrap an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a separate error on shutdown though, it needs to be logged?

@@ -45,7 +45,7 @@ func (svc *serviceCore) setupLogging() {
svc.log = logBuilder.WithConfiguration(svc.logConfig).Build()
ulog.SetLogger(svc.log)
} else {
svc.log.Debug("Using custom log provider due to service.WithLogger option")
ulog.Logger(context.Background()).Debug("Using custom log provider due to service.WithLogger option")
Copy link

Choose a reason for hiding this comment

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

What does this log message even mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a service.WithLogger option during the service setup (similar to WithModule, etc). If that is set, we don't update the service.Logger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see this is a confusing debug message though, will update.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 92.554% when pulling 6c4e538 on with-logger into ec29e35 on master.

@madhuravi madhuravi changed the title Remove hots Logger() access in favor of ctx logger Remove host Logger() access in favor of ctx logger Feb 16, 2017
ulog/log.go Outdated
@@ -140,11 +140,13 @@ func Logger(ctx context.Context) Log {
}

// NewLogContext sets the context with the context aware logger
func NewLogContext(ctx context.Context) context.Context {
func NewLogContext(ctx context.Context, log Log) context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

why pass this in explicitly? just use ulog.Logger() here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used when middleware sets up Log object on the context with module specific fields.

service/host.go Outdated
@@ -95,7 +95,7 @@ func (s *host) IsRunning() bool {
func (s *host) OnCriticalError(err error) {
shutdown := true
if s.observer == nil {
s.Logger().Warn(
s.log.Warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

If we decide on using the ulog.Logger, maybe we should be consistent and use it everywhere in our code. We don't have access to context here but so do service owners in some cases and we still expect them to inject a context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was initially thinking to use s.log internally, only for setup purpose, but you are right that we should be consistent. I'll remove log object on the host itself.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 92.618% when pulling de99f5d on with-logger into ec29e35 on master.

ulog/log.go Outdated
@@ -140,11 +140,13 @@ func Logger(ctx context.Context) Log {
}

// NewLogContext sets the context with the context aware logger
func NewLogContext(ctx context.Context) context.Context {
func NewLogContext(ctx context.Context, log Log) context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

mild preference for method be to ContextWithLogger

Copy link
Collaborator

Choose a reason for hiding this comment

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

more than mind here

// TODO (madhu): Add other middleware - logging, metrics.
module := &Module{
ModuleBase: *modules.NewModuleBase(mi.Name, mi.Host, []string{}),
handlers: handlers,
fcb: defaultFilterChainBuilder(mi.Host),
fcb: defaultFilterChainBuilder(log, mi.Host.AuthClient()),
Copy link
Contributor

Choose a reason for hiding this comment

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

why not set ulog.SetLogger and access ulog.Logger from contextFilter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SetLogger updates the global logger, we don't want to set it to be uhttp specific.


if log != nil {
return context.WithValue(ctx, internal.ContextLogger, log)
}
return context.WithValue(ctx, internal.ContextLogger, logger())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

likewise, WithTracingAware would be ContextWithTraceLogger, along those lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated both.

Copy link
Contributor

@madhuravi madhuravi left a comment

Choose a reason for hiding this comment

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

Can a repo initialize two services with UberFx? How would the global ulog.Logger work in that case?

}
module.config = *cfg

module.log = module.Host().Logger().With("moduleName", mi.Name)
module.log = log
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, logging on Start/Stop module

if err != nil {
ulog.Logger(context.Background()).Info("Logging configuration is not provided, setting to default logger", "error", err)
}
var _simpleCtx = context.Background()
Copy link

Choose a reason for hiding this comment

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

nit, it is actually empty context, probably should name _emptyCtx?

Copy link

Choose a reason for hiding this comment

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

Although, since it is used only for logger, can we have an _svcLogger = ulog.Logger(_simpleCtx)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its better that we use ulog.Logger(_simpleCtx) in service. If we have context based objects in the future, we will have use of _simpleContext.

@coveralls
Copy link

coveralls commented Feb 17, 2017

Coverage Status

Coverage decreased (-0.04%) to 92.581% when pulling 4d52a23 on with-logger into ec29e35 on master.

@anuptalwalkar anuptalwalkar merged commit 3784185 into master Feb 17, 2017
@anuptalwalkar anuptalwalkar deleted the with-logger branch February 17, 2017 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants