lib/log: initial implementation
Created by: bobheadxi
Sets up an initial draft of the logging library, and what the implementation might look like. Closes https://github.com/sourcegraph/sourcegraph/issues/33953 , closes https://github.com/sourcegraph/sourcegraph/issues/33477, closes https://github.com/sourcegraph/sourcegraph/issues/33474 as part of https://github.com/sourcegraph/sourcegraph/issues/33192
- What this might look like in action: https://github.com/sourcegraph/sourcegraph/pull/34155
- Usage docs: see
add_and_use_logging
- Main public APIs:
Some core concepts:
- Do not export directly usable log functions. We want to encourage users to hold their own references to loggers, so that fields can be attached.
2. Internally we still maintain a global logger with
Resource
information though, which tracks the current program. - Export a subset of Zap API. Hopefully, users of this package will never have to import zap directly. Whether or not that's a good idea yet... not sure, but I think it is - makes the API surface much smaller
- Related - we're only exporting the strongly typed logger implementation. Too verbose? Maybe, but I think this interface is better than the
log15
-likeSugaredLogger
, and in combination with restricted API avoids having giant objects be logged. - If we're okay with this, it makes https://github.com/sourcegraph/sourcegraph/issues/33473 much easier, because we can just hook into the re-exported
Field
constructors
- Related - we're only exporting the strongly typed logger implementation. Too verbose? Maybe, but I think this interface is better than the
- The standard logger tries its hardest to be OpenTelemtry-compliant https://opentelemetry.io/docs/reference/specification/logs/data-mode , and as such requires some slight hackery with
zapAdapter
- Desired (distant) end state: ban imports of
log15
,log
,zap
, etc. - all logging must handle bylog.Scoped()
and then using that
Prior art:
Currently not in scope:
- Integrations with other observability packages and constructs https://github.com/sourcegraph/sourcegraph/issues/34217#issuecomment-1105357381
- Dynamic log levels (log levels are currently configured once on init) https://github.com/sourcegraph/sourcegraph/issues/33475
Test plan
unit tests and manual tests. this is mostly pretty self-contained at the moment