Skip to content

Commit

Permalink
feat: add olog package (#420)
Browse files Browse the repository at this point in the history
Adds a new `olog` package with the intent of replacing the existing
`log`
package. Based off of the Go Observability Tooling design document[^1].

For those without access to that document, the main goals are
encapsulated
below:

- Uses `*slog.Logger` as the returned logging library ([Highly
recommended
   read about the library](https://go.dev/blog/slog))
- Loggers must be instantiated with `New()` before a log line can be
emitted,
   there is no singleton provided by the olog package.  
- Packages should create their own logger(s) as required, storing it as
a
package-level global singleton for ease of use (however, loggers can
also
   be created on the fly).
- Default global logging level of Info, which all `New()` loggers
respect.
  Ability to change log level at a module and package level. Adjustable 
  through configuration while the process is still running.
- Creating wrapped loggers using a provided `*slog.Logger` (ideally from
   `New()`) to enable Outreach-specific functionality, like audit logs.
- Pretty printing of logs by default when `os.Stderr` is a TTY (local
development).
- Automatically log otel-logging compliant TraceID and SpanID if a
context with
   trace information is passed to the logger.
  - **This will require <Level>Context function calls to work.**

Expected usage is calling `New` to create new logger _per package_. This
should
be done either as a global variable per-package, or once per-package and
passed
around.

Provides a test helper (`NewTestCapturer`) that enables callers to
capture all log
output for the purpose of checking the output/result of certain
operations via logs.
This is primarily intended to be used only for the development of the
logger, since
logs are not a stable way to ensure an operation has occurred.

[^1]:
https://outreach-io.atlassian.net/wiki/spaces/DT/pages/2853765388/Go+Observability+Tooling+Design#Logging

---------

Co-authored-by: Jared Allard <[email protected]>
Co-authored-by: Professor X <[email protected]>
Co-authored-by: Alex Hester <[email protected]>
Co-authored-by: Mark Lee <[email protected]>
Co-authored-by: Devbase CI <[email protected]>
  • Loading branch information
6 people authored Feb 14, 2024
1 parent 7275803 commit 1b95767
Show file tree
Hide file tree
Showing 22 changed files with 2,386 additions and 63 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ golang 1.21.3
# while leaving the 'default' version intact for the infra.
# The most common case is nodejs.
## <<Stencil::Block(toolver)>>
golangci-lint 1.55.1
## <</Stencil::Block>>
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/getoutreach/gobox

go 1.19
go 1.21

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.2.1
github.com/briandowns/spinner v1.23.0
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/log v0.3.1
github.com/creack/pty v1.1.21
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.16.0
Expand Down Expand Up @@ -49,9 +50,11 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
Expand All @@ -60,6 +63,7 @@ require (
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/tdewolff/parse/v2 v2.7.11 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
)
Expand Down Expand Up @@ -93,14 +97,14 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common v0.45.0 // indirect
Expand Down
31 changes: 28 additions & 3 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go 1.21

use .

use ./pkg/ometrics
Loading

0 comments on commit 1b95767

Please sign in to comment.