Minimal structured logging library for Go

slog

GitHub Release GoDoc Coveralls CI Status

slog is a minimal structured logging library for Go.

Install

go get cdr.dev/slog

Features

Example

Many more examples available at godoc.

log := slog.Make(sloghuman.Sink(os.Stdout))

log.Info(context.Background(), "my message here",
    slog.F("field_name", "something or the other"),
    slog.F("some_map", slog.M(
        slog.F("nested_fields", time.Date(2000, time.February, 5, 4, 4, 4, 0, time.UTC)),
    )),
    slog.Error(
        xerrors.Errorf("wrap1: %w",
            xerrors.Errorf("wrap2: %w",
                io.EOF,
            ),
        ),
    ),
)

Example output screenshot

Why?

At Coder we’ve used Uber’s zap for several years. It is a fantastic library for performance. Thanks Uber!

However we felt the API and developer experience could be improved.

Here is a list of reasons how we improved on zap with slog.

  1. slog has a minimal API surface

    • Compare slog to zap and zapcore.
    • The sprawling API makes zap hard to understand, use and extend.
  2. slog has a concise semi typed API

    • We found zap's fully typed API cumbersome. It does offer a sugared API but it's too easy to pass an invalid fields list since there is no static type checking. Furthermore, it's harder to read as there is no syntax grouping for each key value pair.
    • We wanted an API that only accepted the equivalent of zap.Any for every field. This is slog.F.
  3. sloghuman uses a very human readable format

    • It colors distinct parts of each line to make it easier to scan logs. Even the JSON that represents the fields in each log is syntax highlighted so that is very easy to scan. See the screenshot above.
      • zap lacks appropriate colors for different levels and fields
    • slog automatically prints one multiline field after the log to make errors and such much easier to read.
      • zap logs multiline fields and errors stack traces as JSON strings which made them unreadable in a terminal.
    • When logging to JSON, slog automatically converts a golang.org/x/xerrors chain into an array with fields for the location and wrapping messages.
  4. Full context.Context support

    • slog lets you set fields in a context.Context such that any log with the context prints those fields.
    • We wanted to be able to pull up all relevant logs for a given trace, user or request. With zap, we were plugging these fields in for every relevant log or passing around a logger with the fields set. This became very verbose.
  5. Simple and easy to extend

    • A new backend only has to implement the simple Sink interface.
    • The Logger type provides a nice API around Sink but also implements Sink to allow for composition.
    • zap is hard and confusing to extend. There are too many structures and configuration options.
  6. Structured logging of Go structures with json.Marshal

    • Entire encoding process is documented on godoc.
    • With zap, We found ourselves often implementing zap's ObjectMarshaler to log Go structures. This was verbose and most of the time we ended up only implementing fmt.Stringer and using zap.Stringer instead.
  7. slog takes inspiration from Go's stdlib and implements slog.Helper which works just like t.Helper

    • It marks the calling function as a helper and skips it when reporting location info.
    • We had many helper functions for logging but we wanted the line reported to be of the parent function. zap has an API for this but it's verbose and requires passing the logger around explicitly.
  8. Tight integration with stdlib's testing package

    • You can configure slogtest to exit on any ERROR logs and it has a global stateless API that takes a testing.TB so you do not need to create a logger first.
    • Test assertion helpers are provided in slogtest/assert.
    • zap has zaptest but the API surface is large and doesn't integrate well. It does not support any of the features described above.
Owner
Coder
We make it easy to write more code.
Coder
Comments
  • Reconsider number of logging levels

    Reconsider number of logging levels

    See @peterbourgon's criticism at https://lobste.rs/s/tofgzk/cdr_slog_minimal_structured_logging#c_beo2sc

    I fully agree regarding the logging levels. I do want to minimize the number of logs.

    Will require some thought.

    @cdr/engineering

  • chore: bump cloud.google.com/go/compute from 0.1.0 to 1.6.1

    chore: bump cloud.google.com/go/compute from 0.1.0 to 1.6.1

    Bumps cloud.google.com/go/compute from 0.1.0 to 1.6.1.

    Release notes

    Sourced from cloud.google.com/go/compute's releases.

    compute: v1.6.1

    1.6.1 (2022-04-21)

    Bug Fixes

    • compute: revert proto3_optional, required removal on parent_id (#714) (d4ea7dd)

    aiplatform: v1.6.0

    1.6.0 (2022-03-14)

    Features

    compute: v1.6.0

    1.6.0 (2022-04-14)

    Features

    • compute: update compute API to revision 20220322 (#710) (bb5da6b)

    Bug Fixes

    • compute: remove proto3_optional from parent_id (#712) (19a9ef2)
    • compute: replace missing REQUIRED for parent_id (#711) (19a9ef2)

    securitycenter: v1.6.0

    1.6.0 (2022-04-14)

    Features

    • securitycenter: Add iam_binding field to findings attributes. It represents particular IAM bindings, which captures a member's role addition, removal, or state (bb5da6b)
    • securitycenter: Add next_steps field to finding's list of attributes (19a9ef2)

    osconfig: v1.5.0

    1.5.0 (2022-02-23)

    Features

    • osconfig: set versionClient to module version (55f0d92)

    securitycenter: v1.5.0

    1.5.0 (2022-03-14)

    ... (truncated)

    Changelog

    Sourced from cloud.google.com/go/compute's changelog.

    Changes

    0.101.0 (2022-04-20)

    Features

    Bug Fixes

    • internal/gapicgen: add generation of internal/version.go for new client modules (#5726) (341e0df)
    • internal/gapicgen: don't gen version files for longrunning and debugger (#5698) (3a81108)
    • internal/gapicgen: don't try to make snippets for non-gapics (#5919) (c94dddc)
    • internal/gapicgen: move breaking change indicator if present (#5452) (e712df5)
    • internal/godocfx: prevent errors for filtered mods (#5485) (6cb9b89)

    0.100.0 (2022-01-04)

    Features

    • analytics/admin: add the AcknowledgeUserDataCollection operation which acknowledges the terms of user data collection for the specified property feat: add the new resource type DataStream, which is planned to eventually replace WebDataStream, IosAppDataStream, AndroidAppDataStream resources fix!: remove GetEnhancedMeasurementSettings, UpdateEnhancedMeasurementSettingsRequest, UpdateEnhancedMeasurementSettingsRequest operations from the API feat: add CreateDataStream, DeleteDataStream, UpdateDataStream, ListDataStreams operations to support the new DataStream resource feat: add DISPLAY_VIDEO_360_ADVERTISER_LINK, DISPLAY_VIDEO_360_ADVERTISER_LINK_PROPOSAL fields to ChangeHistoryResourceType enum feat: add the account field to the Property type docs: update the documentation with a new list of valid values for UserLink.direct_roles field (5444809)
    • assuredworkloads: EU Regions and Support With Sovereign Controls (5444809)
    • dialogflow/cx: added the display name of the current page in webhook requests (e0833b2)
    • dialogflow/cx: added the display name of the current page in webhook requests (e0833b2)
    • dialogflow: added export documentation method feat: added filter in list documentations request feat: added option to import custom metadata from Google Cloud Storage in reload document request feat: added option to apply partial update to the smart messaging allowlist in reload document request feat: added filter in list knowledge bases request (5444809)
    • dialogflow: removed OPTIONAL for speech model variant docs: added more docs for speech model variant and improved docs format for participant (5444809)
    • recaptchaenterprise: add new reCAPTCHA Enterprise fraud annotations (3dd34a2)

    Bug Fixes

    • artifactregistry: fix resource pattern ID segment name (5444809)
    • compute: add parameter in compute bazel rules (#692) (5444809)
    • profiler: refine regular expression for parsing backoff duration in E2E tests (#5229) (4438aeb)
    • profiler: remove certificate expiration workaround (#5222) (2da36c9)

    0.99.0 (2021-12-06)

    Features

    • dialogflow/cx: added TelephonyTransferCall in response message (fe27098)

    0.98.0 (2021-12-03)

    ... (truncated)

    Commits
    • 407eb37 chore: release pubsub/v1.6.1 (#2648)
    • 0f60593 fix(pubsub): parse EnableMessageOrdering on GetSubscription (#2647)
    • 29aebdf feat(firestore): implement limitToLast (#2420)
    • f942d35 chore(all): update all (#2642)
    • bfdc8db fix(storage): add retry for TestIntegration_DeleteObjectInBucketWithRetention...
    • a2be9c9 feat(all): auto-regenerate gapics (#2641)
    • 94ec136 feat(all): auto-regenerate gapics (#2639)
    • 4b2f0b9 feat(all): auto-regenerate gapics (#2638)
    • 22b9552 fix(profiler): fix order of units in regexp used to parse backoff duration (#...
    • 5ea6f1f feat(all): auto-regenerate gapics (#2636)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Nuke go.mod/go.sum and recreate

    Nuke go.mod/go.sum and recreate

    slog's been giving people trouble building terrastruct/d2 from source. Something's wrong with the google cloud dependencies. Hopefully this fixes things.

  • chore: bump cloud.google.com/go from 0.83.0 to 0.84.0

    chore: bump cloud.google.com/go from 0.83.0 to 0.84.0

    Bumps cloud.google.com/go from 0.83.0 to 0.84.0.

    Release notes

    Sourced from cloud.google.com/go's releases.

    google-cloud-go v0.84.0

    Features

    • aiplatform: start generating apiv1 (be1d729)
    • apigeeconnect: start generating abiv1 (be1d729)
    • dialogflow/cx: support sentiment analysis in bot testing (7a57aac)
    • dialogflow/cx: support sentiment analysis in bot testing (6ad2306)
    • documentai: Move CommonOperationMetadata into a separate proto file for potential reuse. (9e80ea0)
    • documentai: Move CommonOperationMetadata into a separate proto file for potential reuse. (18375e5)
    • gkeconnect/gateway: start generating apiv1beta1 (#4235) (1c3e968)
    • lifesciences: strat generating apiv2beta (be1d729)
    • tpu: start generating apiv1 (#4199) (cac48ea)

    Bug Fixes

    • bttest: fix race condition in SampleRowKeys (#4207) (5711fb1)
    • documentai: Fix Ruby gem title of documentai v1 (package not currently published) (9e80ea0)
    Changelog

    Sourced from cloud.google.com/go's changelog.

    0.84.0 (2021-06-09)

    Features

    • aiplatform: start generating apiv1 (be1d729)
    • apigeeconnect: start generating abiv1 (be1d729)
    • dialogflow/cx: support sentiment analysis in bot testing (7a57aac)
    • dialogflow/cx: support sentiment analysis in bot testing (6ad2306)
    • documentai: Move CommonOperationMetadata into a separate proto file for potential reuse. (9e80ea0)
    • documentai: Move CommonOperationMetadata into a separate proto file for potential reuse. (18375e5)
    • gkeconnect/gateway: start generating apiv1beta1 (#4235) (1c3e968)
    • lifesciences: strat generating apiv2beta (be1d729)
    • tpu: start generating apiv1 (#4199) (cac48ea)

    Bug Fixes

    • bttest: fix race condition in SampleRowKeys (#4207) (5711fb1)
    • documentai: Fix Ruby gem title of documentai v1 (package not currently published) (9e80ea0)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Unable to use v2

    Unable to use v2

    I get the following error when trying to import v2 of the logger: go get cdr.dev/[email protected]: cdr.dev/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

    go get cdr.dev/[email protected]: cdr.dev/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

  • Configurable human logger

    Configurable human logger

    The human logger should allow for a configuration struct which lets the developer hide things like the timestamp and file name. We could also allow for forcibly disabling colors through this config struct too.

    package sloghuman
    
    type Config struct {
        HideTimestamp bool
        HideFile bool
        ...
    }
    
    func MakeConfig(w io.Writer, c Config) slog.Logger {}
    
  • Format alternate nested arrays without dash

    Format alternate nested arrays without dash

    Will improve our xerrors formatting a lot.

    Though tbh it’d seem really bizarre to not have fields for loc and whatnot cause the number of fields is fixed and it’s semantically a map.

  • chore: bump cloud.google.com/go from 0.94.0 to 0.94.1

    chore: bump cloud.google.com/go from 0.94.0 to 0.94.1

    Bumps cloud.google.com/go from 0.94.0 to 0.94.1.

    Release notes

    Sourced from cloud.google.com/go's releases.

    google-cloud-go v0.94.1

    Bug Fixes

    • compute/metadata: fix retry logic to not panic on error (#4714) (75c63b9), refs #4713
    Changelog

    Sourced from cloud.google.com/go's changelog.

    0.94.1 (2021-09-02)

    Bug Fixes

    • compute/metadata: fix retry logic to not panic on error (#4714) (75c63b9), refs #4713
    Commits
    • 0055466 chore: release 0.94.1 (#4716)
    • 75c63b9 fix(compute/metadata): fix retry logic to not panic on error (#4714)
    • a0f7a02 feat(firestore): Support DocumentRefs in OrderBy, Add Query.Serialize, Query....
    • d6d4a3c test(pubsublite): fix flaky TestAssigningSubscriberAddRemovePartitions (#4564)
    • 27c3ed0 chore: release storage 1.16.1 (#4441)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore: bump cloud.google.com/go from 0.91.1 to 0.93.3

    chore: bump cloud.google.com/go from 0.91.1 to 0.93.3

    Bumps cloud.google.com/go from 0.91.1 to 0.93.3.

    Release notes

    Sourced from cloud.google.com/go's releases.

    v0.92.3

    As of this release the following directories have been made into their own standalone module:

    • cloudbuild
    • monitoring
    • analytics
    • area120
    • gkeconnect
    • gkehub
    • grafeas
    • security
    • video
    • secretmanager

    This means they will no longer be found in the root cloud.google.com/go module. When updating your code running go mod tidy should start pulling in the new sub-modules.

    v0.92.2

    Announcement

    As of this release the following directories have been made into their own standalone module:

    • datastream
    • dialogflow
    • dlp
    • documentai
    • domains
    • errorreporting
    • essentialcontacts
    • eventarc
    • functions
    • gaming
    • gsuiteaddons
    • iap
    • iot
    • kms
    • language
    • lifesciences
    • managedidentities
    • mediatranslation
    • memcache
    • metastore
    • networkconnectivity
    • networkmanagement
    • notebooks
    • orgpolicy
    • osconfig
    • oslogin
    • phishingprotection
    • policytroubleshooter
    • privatecatalog
    • profiler

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • chore: bump cloud.google.com/go from 0.91.1 to 0.92.1

    chore: bump cloud.google.com/go from 0.91.1 to 0.92.1

    Bumps cloud.google.com/go from 0.91.1 to 0.92.1.

    Release notes

    Sourced from cloud.google.com/go's releases.

    v0.92.1

    Announcement

    As of this release the following directories have been made into their own standalone module:

    • accessapproval
    • aiplatform
    • apigateway
    • apigeeconnect
    • appengine
    • artifactregistry
    • asset
    • assuredworkloads
    • automl
    • billing
    • binaryauthorization
    • channel
    • clouddms
    • cloudtasks
    • container
    • containeranalysis
    • datacatalog
    • dataflow
    • datafusion
    • datalabeling
    • dataproc
    • dataqna

    This means they will no longer be found in the root cloud.google.com/go module. When updating your code running go mod tidy should start pulling in the new sub-modules.

    google-cloud-go v0.92.0

    Features

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • I Get A Garbled results

    I Get A Garbled results

    2019-12-13 02:02:43.229 ?[34m[INFO]?[0m ?[36macc.go:19?[0m my message here {?[34m"field_name"?[0m: ?[32m"something or the other"?[0m, ?[34m"some_map"?[0m: {?[34m"nested_fields"?[0m: ?[32m"wowow"?[0m}} ... ?[34m"error"?[0m: wrap1: main.main C:/Users/xxx/Desktop/gotest/acc.go:25 - wrap2: main.main C:/Users/xxx/Desktop/gotest/acc.go:26 - EOF

  • chore: bump cloud.google.com/go from 0.26.0 to 0.107.0

    chore: bump cloud.google.com/go from 0.26.0 to 0.107.0

    Bumps cloud.google.com/go from 0.26.0 to 0.107.0.

    Release notes

    Sourced from cloud.google.com/go's releases.

    v0.107.0

    0.107.0 (2022-11-15)

    Features

    v0.106.0

    0.106.0 (2022-11-09)

    Features

    • debugger: rewrite signatures in terms of new location (3c4b2b3)
    Changelog

    Sourced from cloud.google.com/go's changelog.

    0.107.0 (2022-11-15)

    Features

    0.106.0 (2022-11-09)

    Features

    • debugger: rewrite signatures in terms of new location (3c4b2b3)

    0.104.0 (2022-08-24)

    Features

    0.103.0 (2022-06-29)

    Features

    • privateca: temporarily remove REGAPIC support (199b725)

    0.102.1 (2022-06-17)

    Bug Fixes

    • longrunning: regapic remove path params duped as query params (#6183) (c963be3)

    0.102.0 (2022-05-24)

    Features

    • civil: add Before and After methods to civil.Time (#5703) (7acaaaf)

    0.101.1 (2022-05-03)

    Bug Fixes

    • internal/gapicgen: properly update modules that have no gapic changes (#5945) (de2befc)

    0.101.0 (2022-04-20)

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Terminal control characters are not always escaped safely

    Terminal control characters are not always escaped safely

    Not sure whether or not this is considered a feature or a bug, but in certain scenarios, terminal escape chars are interpreted as-is, and in other they're escaped into string form.

    package main
    
    import (
    	"context"
    	"os"
    
    	"cdr.dev/slog"
    	"cdr.dev/slog/sloggers/sloghuman"
    )
    
    func main() {
    	ctx := context.Background()
    	log := slog.Make(sloghuman.Sink(os.Stderr))
    	log.Info(ctx, "test1\r\nw\reird\a")
    	log.Info(ctx, "test2", slog.F("boop", "hello\r\nb\rell\a"))
    	log.Info(ctx, "test3\r\nt\rest", slog.F("boop", "hello\r\nb\rell\a"))
    	log.Info(ctx, "test4", slog.F("clipboard", "\033]52;c;surprise!\a"))
    }
    
    // Output:
    2022-11-10 18:10:11.256 [INFO]	<main.go:18>	main	...
      "msg": test1
    eird     w
    2022-11-10 18:10:11.256 [INFO]	<main.go:19>	main	test2 ...
      "boop": hello
    ell       b
    2022-11-10 18:10:11.256 [INFO]	<main.go:20>	main	...	{"boop": "hello\r\nb\rell\u0007"}
      "msg": test3
    est      t
    2022-11-10 18:10:11.257 [INFO]	<main.go:21>	main	test4	{"clipboard": "\u001b]52;c;surprise!\u0007"}
    

    Pretty printing \r\n seems intended and like a nice feature (since it's aligned), but stray \r and also \a are interpreted as-is. The latter (\a) will also ring the terminal bell which I would venture is never the expectation.

    Out of these 4 cases, only the clipboard case behaved as I would expect.

  • Some level of background logging

    Some level of background logging

    When a route is log heavy, the response shouldn't wait for all the logs to be marshalled/written.

    Right now it's the job of the sync but perhaps we should provide a configurable general wrapper for io.Writer.

  • Implement api to accept empty error

    Implement api to accept empty error

    Zerolog has this nifty api log.Err(err error) that is Error level if err != nil and Info level if err == nil

    The basic gist to avoid this common code:

    authenticated, err := auth()
    if err != nil {
      slog.Error(ctx, "failed to authorize user"
        slog.Error(err),
        slog.F("user", "alice")
      )
      return
    }
    
    slog.Info(ctx, "authorized user",
        slog.F("user", "alice"),
    )
    ...
    

    and you can just do (the message becomes the action, and the Error level indicates the action failed):

    authenticated, err := auth()
    // Unsure exactly on the API, still adapting to slog, so unsure what would be "natural" 
    slog.Err(err).(ctx, "authorize user", 
      slog.F("user", "alice")
    )
    
    if err != nil {
      return
    }
    ...
    

    It is a small feature I miss. Let me know what you think.

  • Add package level functions for logging to the stderr logger

    Add package level functions for logging to the stderr logger

    Right now it's relatively difficult to find the default logger to use if an explicit logger is not available. It would be nice to be able to do

    slog.Error(...)
    
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Sep 26, 2022
Hierarchical, leveled, and structured logging library for Go

spacelog Please see http://godoc.org/github.com/spacemonkeygo/spacelog for info License Copyright (C) 2014 Space Monkey, Inc. Licensed under the Apach

Apr 27, 2021
A minimal and extensible structured logger

⚠️ PRE-RELEASE ⚠️ DO NOT IMPORT THIS MODULE YOUR PROJECT WILL BREAK package log package log provides a minimal interface for structured logging in ser

Jan 7, 2023
Structured logging package for Go.
Structured logging package for Go.

Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on Medium. Handlers apexlog

Dec 24, 2022
Simple, configurable and scalable Structured Logging for Go.

log Log is a simple, highly configurable, Structured Logging library Why another logging library? There's allot of great stuff out there, but also tho

Sep 26, 2022
Structured, composable logging for Go
Structured, composable logging for Go

log15 Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is mo

Dec 18, 2022
Structured, pluggable logging for Go.
Structured, pluggable logging for Go.

Logrus Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger. Logrus is in maintenance-mode. We wi

Jan 9, 2023
Structured Logging Made Easy
Structured Logging Made Easy

Structured Logging Made Easy Features Dependency Free Simple and Clean Interface Consistent Writer IOWriter, io.Writer wrapper FileWriter, rotating &

Jan 3, 2023
Blazing fast, structured, leveled logging in Go.

⚡ zap Blazing fast, structured, leveled logging in Go. Installation go get -u go.uber.org/zap Note that zap only supports the two most recent minor ve

Jan 7, 2023
Logrus is a structured, pluggable logging for Go.
Logrus is a structured, pluggable logging for Go.

Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.

May 25, 2021
Fully asynchronous, structured, pluggable logging for Go.

logr Logr is a fully asynchronous, contextual logger for Go. It is very much inspired by Logrus but addresses two issues: Logr is fully asynchronous,

Dec 28, 2022
structured logging helper

Logart Logart is a structured logging tool that aims to simplify logging to a database It is not yet in stable state, but is used in production and ac

Apr 24, 2021
Go-metalog - Standard API for structured logging

Metalog is a standard API for structured logging and adapters for its implementa

Jan 20, 2022
📝 🪵 A minimal level based logging library for Go

slogx A minimal level based logging library for Go. Installation Example Usage Logger Log Level Format Output Contribute License Installation go get g

May 23, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

FactorLog FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily b

Aug 3, 2022
Package logging implements a logging infrastructure for Go
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Nov 10, 2021
a lightweight, high-performance, out-of-the-box logging library that relies solely on the Go standard library

English | 中文 olog olog is a lightweight, high-performance, out-of-the-box logging library that relies solely on the Go standard library. Support outpu

Apr 12, 2023
Structured log interface

Structured log interface Package log provides the separation of the logging interface from its implementation and decouples the logger backend from yo

Sep 26, 2022