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

Suppress debug-level SDK logs in tests #16

Open
mark-rushakoff opened this issue Oct 30, 2024 · 0 comments
Open

Suppress debug-level SDK logs in tests #16

mark-rushakoff opened this issue Oct 30, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@mark-rushakoff
Copy link
Member

There are many SDK logs with level=DEBUG that are usually not interesting to us in gcosmos tests:

    logger.go:257: time=2024-10-30T20:08:34.684Z level=DEBUG msg="running initialization for module" val_idx=0 module=consensus
    logger.go:257: time=2024-10-30T20:08:34.684Z level=DEBUG msg="running initialization for module" val_idx=0 module=accounts
...
    logger.go:257: time=2024-10-30T20:08:34.712Z level=DEBUG msg=recursiveRemove val_idx=0 node="Node{1:\n@ <nil>:- 1-0 }#\n" key="C\x00\x00\x00\x00\x00\x00\x00\x1d1970-01-01T00:00:00.000000000\x00\x00\x00\x00\x00\x00\x00\x00"
...
    logger.go:257: time=2024-10-30T20:08:34.720Z level=DEBUG msg="BATCH SAVE" val_idx=0 node="Node{\x06:@ (1, 1):000000000000000100000002-000000000000000100000009 7-3 83f6aa9b551fb61d24a9e047ada4be5e6a9f0968a23f72ffe2ffaee700dd13e1}#{left (1, 2)}{right (1, 9)}\n"
    logger.go:257: time=2024-10-30T20:08:34.720Z level=DEBUG msg="SAVE TREE" val_idx=0 version=1

The gcosmos tests call gcosmos/internal/copy/gtest.NewTestLogger to produce the test logger:

// NewLogger returns a *slog.Logger associated with the test t.
func NewLogger(t testing.TB) *slog.Logger {
// The slogt package has been stable and effective
// for adapting slog to testing.T.Log calls.
// Prefer to abstract slogt behind a gtest interface
// to reduce a direct dependency from tests to an external module.
return slogt.New(t, slogt.Text())
}

Change that plain call to slogt.New to use slogt.Bridge. Continue to use the Text handler, but set the Bridge's Handle method to drop records that have level debug and that do not have root=gcosmos, so that we can still see gcosmos debug logs by default.

@mark-rushakoff mark-rushakoff added the good first issue Good for newcomers label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant