-
Notifications
You must be signed in to change notification settings - Fork 419
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
Allow loggers to be passed in #902
Conversation
Motivation: The community recently discussed how logging should be done for the `AsyncHTTPClient` project. One of the outcomes was that frameworks should not log unless they are explicitly passed a logger. This allows applications to decide whether they care about logging for that component and have more control over the level at which that component logs at. Modifications: - Client allows for loggers in two places: one for background activity (connectivity state management and so on) and another for RPCs - Server allows a single logger to be specificed - By default all loggers are no-op loggers - Added 'none' option for 'CallOptions.RequestIDProvider' for cases where the request ID is already present on the logger Result: - gRPC does not log by default - Note: this includes tests, this will be addressed in a separate PR to keep PR size down
@@ -536,7 +549,8 @@ extension ClientConnection { | |||
connectionKeepalive: ClientConnectionKeepalive = ClientConnectionKeepalive(), | |||
connectionIdleTimeout: TimeAmount = .minutes(5), | |||
callStartBehavior: CallStartBehavior = .waitsForConnectivity, | |||
httpTargetWindowSize: Int = 65535 | |||
httpTargetWindowSize: Int = 65535, | |||
backgroundActivityLogger: Logger = Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }) |
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 it worth encapsulating this in a static func
on Logger
we define internally, just so we have one-and-only-one place to write this code?
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 has to be public
as it's used in a public
signature. I wasn't sure making it underscored-internal was worth it in this case.
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.
Ok, fair enough. 😄
Sources/GRPC/ClientOptions.swift
Outdated
public init( | ||
customMetadata: HPACKHeaders = HPACKHeaders(), | ||
timeLimit: TimeLimit = .none, | ||
messageEncoding: ClientMessageEncoding = .disabled, | ||
requestIDProvider: RequestIDProvider = .autogenerated, | ||
requestIDProvider: RequestIDProvider = .none, |
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's the reason for this change?
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 seemed more natural to opt-in to having request IDs generated rather than opting out. Not sure how much I agree with that thinking now. WDYT?
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'm inclined to want to go to "fall into a pit of success": if users don't express a preference, giving them nice UUIDs makes their lives easier, and also our own during bug triage.
Sources/GRPC/PlatformSupport.swift
Outdated
@@ -155,23 +153,22 @@ public enum PlatformSupport { | |||
networkPreference: NetworkPreference = .best, | |||
logger: Logger? = nil |
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 are we defaulting the loggers in this file to nil
as opposed to the no-op 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 don't think there's a good reason to use an optional logger here; I just didn't think to change it.
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.
LGTM,
Motivation: In grpc#902 we changed behaviour such that gRPC will not log unless you explicitly pass in a logger. When tests fail it's useful to have the logs to triage them, especially when they fail under CI, for example. Modifications: - Add a capturing log handler to the test module which captures all emitted logs - Wire up loggers in tests - Hook up `GRPCTestCase` to print the captured logs only if a test fails (or an environment variable was set) - Add a bunch of missing `super.setUp` and `super.tearDown` calls Result: - If a test fails we get all `.trace` level logs emitted during that test
Motivation: In grpc#902 we changed behaviour such that gRPC will not log unless you explicitly pass in a logger. When tests fail it's useful to have the logs to triage them, especially when they fail under CI, for example. Modifications: - Add a capturing log handler to the test module which captures all emitted logs - Wire up loggers in tests - Hook up `GRPCTestCase` to print the captured logs only if a test fails (or an environment variable was set) - Add a bunch of missing `super.setUp` and `super.tearDown` calls Result: - If a test fails we get all `.trace` level logs emitted during that test
Motivation: In grpc#902 we changed behaviour such that gRPC will not log unless you explicitly pass in a logger. When tests fail it's useful to have the logs to triage them, especially when they fail under CI, for example. Modifications: - Add a capturing log handler factory to the test module which captures all logs emitted by handlers it makes - Wire up loggers in tests - Hook up `GRPCTestCase` to print the captured logs only if a test fails (or an environment variable was set) - Add a bunch of missing `super.setUp` and `super.tearDown` calls Result: - If a test fails we get all `.trace` level logs emitted during that test
Motivation: In #902 we changed behaviour such that gRPC will not log unless you explicitly pass in a logger. When tests fail it's useful to have the logs to triage them, especially when they fail under CI, for example. Modifications: - Add a capturing log handler factory to the test module which captures all logs emitted by handlers it makes - Wire up loggers in tests - Hook up `GRPCTestCase` to print the captured logs only if a test fails (or an environment variable was set) - Add a bunch of missing `super.setUp` and `super.tearDown` calls Result: - If a test fails we get all `.trace` level logs emitted during that test
Motivation:
The community recently discussed how logging should be done for the
AsyncHTTPClient
project. One of the outcomes was that frameworksshould not log unless they are explicitly passed a logger. This allows
applications to decide whether they care about logging for that
component and have more control over the level at which that component
logs at.
Modifications:
(connectivity state management and so on) and another for RPCs
where the request ID is already present on the logger
Result:
keep PR size down