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

Allow loggers to be passed in #902

Merged
merged 3 commits into from
Jul 20, 2020
Merged

Allow loggers to be passed in #902

merged 3 commits into from
Jul 20, 2020

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jul 20, 2020

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 not logging in tests, this will be addressed in a separate PR to
    keep PR size down

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
@glbrntt glbrntt requested a review from Lukasa July 20, 2020 13:14
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Jul 20, 2020
@@ -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() })
Copy link
Collaborator

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?

Copy link
Collaborator Author

@glbrntt glbrntt Jul 20, 2020

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, fair enough. 😄

public init(
customMetadata: HPACKHeaders = HPACKHeaders(),
timeLimit: TimeLimit = .none,
messageEncoding: ClientMessageEncoding = .disabled,
requestIDProvider: RequestIDProvider = .autogenerated,
requestIDProvider: RequestIDProvider = .none,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

@@ -155,23 +153,22 @@ public enum PlatformSupport {
networkPreference: NetworkPreference = .best,
logger: Logger? = nil
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

LGTM, :shipit:

@glbrntt glbrntt merged commit d4633f2 into grpc:master Jul 20, 2020
@glbrntt glbrntt deleted the gb-logging branch July 20, 2020 14:35
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 20, 2020
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
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 20, 2020
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
glbrntt added a commit to glbrntt/grpc-swift that referenced this pull request Jul 20, 2020
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
@glbrntt glbrntt mentioned this pull request Jul 20, 2020
glbrntt added a commit that referenced this pull request Jul 20, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants