This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes
Sync()
from the logger interface and adds a callback returned bylog.Init
which should be called before application exit. The removal ofSync()
from theLogger
interface helps indicate that not every logger fromlog.Scoped
needs a call toSync()
. Forlogtest
, we add at.Cleanup
func to sync the global logger.From https://github.com/sourcegraph/sourcegraph/pull/34320 I've noticed that
log.Fatal
is used quite liberally. Even if we switch to error propagation, there's still the issue thatos.Exit
will bypass anydefer
calls and hence potentially missSync()
. To accommodate this pattern, I've decided to add backFatal
toLogger
, which internally callsSync()
beforeos.Exit(1)
. Also see uber-go/zap#207 for more rationale for supportingFatal
.Background: All loggers are children of the root global logger that is instantiated once. As such, it is sufficient to just call
Sync()
on the root logger - all child loggers just write to underlying loggers until they reach the root, which as far as I can tell is anos.File
that hasSync()
, which gets called by Zap, so it's not a no-op even if Zap itself does not do any buffering (at the moment, the global logger is not configured to do so)Aside: in practice, it's honestly probably not a huge deal to never call
Sync()
, but we should anyway just in case, so hopefully this balances the probable need to callSync()
with ergonomics.Part of https://github.com/sourcegraph/sourcegraph/issues/33192
Test plan
n/a