-
Notifications
You must be signed in to change notification settings - Fork 281
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
Conversation
@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. |
Do we lose any fidelity here? Is there context on the host logger not
present on ctx?
…On Tue, Feb 14, 2017 at 6:05 PM Coveralls ***@***.***> wrote:
[image: Coverage Status] <https://coveralls.io/builds/10156964>
Coverage decreased (-0.07%) to 92.581% when pulling *b69958d
<b69958d>
on with-logger* into *0626e44
<0626e44>
on master*.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#260 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAF7P8M438Ks-m2LIy_qOgSADXJ1KAFkks5rcl1cgaJpZM4MBOM3>
.
|
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) |
b69958d
to
b64890e
Compare
modules/uhttp/filters_test.go
Outdated
@@ -42,6 +41,7 @@ import ( | |||
"github.com/uber/jaeger-client-go/config" | |||
) | |||
|
|||
<<<<<<< HEAD |
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.
wat?
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.
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) |
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.
Looks like instead of logging here, we should wrap an error.
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.
This is a separate error on shutdown though, it needs to be logged?
service/service_setup.go
Outdated
@@ -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") |
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.
What does this log message even mean?
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.
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
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 can see this is a confusing debug message though, will update.
b64890e
to
6c4e538
Compare
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 { |
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.
why pass this in explicitly? just use ulog.Logger() here
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.
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( |
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.
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.
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 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.
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 { |
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.
mild preference for method be to ContextWithLogger
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.
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()), |
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.
why not set ulog.SetLogger and access ulog.Logger from contextFilter?
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.
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()) | ||
} | ||
|
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.
likewise, WithTracingAware would be ContextWithTraceLogger, along those lines.
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.
updated both.
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.
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 |
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.
Is this used anywhere?
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.
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() |
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.
nit, it is actually empty context, probably should name _emptyCtx?
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.
Although, since it is used only for logger, can we have an _svcLogger = ulog.Logger(_simpleCtx)?
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 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.
No description provided.