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

feat: standardize logging #1302

Merged
merged 51 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
72f96cc
Initial slog switch
zivkovicmilos Oct 26, 2023
9328f52
Change log level
zivkovicmilos Oct 26, 2023
3abfc67
Merge branch 'feat/standardized-logging' into feat/log
zivkovicmilos Oct 26, 2023
a4449bd
Drop the logger backend in tm2
zivkovicmilos Oct 26, 2023
c08de43
Use custom zap config
zivkovicmilos Oct 26, 2023
035bbef
Use log level from config
zivkovicmilos Oct 26, 2023
e6dd5ac
Merge branch 'master' into feat/log
zivkovicmilos Oct 26, 2023
dec3fed
Update workflows
zivkovicmilos Oct 26, 2023
9aa5d7d
Remove test case because of Go 1.21
zivkovicmilos Oct 26, 2023
209041f
Resolve faulty log lines
zivkovicmilos Oct 26, 2023
568ff80
Revert go version change
zivkovicmilos Jan 15, 2024
be13b5d
Merge master
zivkovicmilos Jan 15, 2024
b32ea84
Tidy go mods
zivkovicmilos Jan 15, 2024
32603c2
Switch to /exp/log because of go 1.20
zivkovicmilos Jan 15, 2024
71787aa
Update gnodev logger usage:
zivkovicmilos Jan 15, 2024
28bebde
Please the go mod gods
zivkovicmilos Jan 15, 2024
5db0ddb
Add logger err case
zivkovicmilos Jan 15, 2024
13fefe7
Merge branch 'master' into feat/log
zivkovicmilos Jan 15, 2024
33f1934
fix: use zap logger specific initialization
gfanton Jan 15, 2024
75c7285
Resolve API changes
zivkovicmilos Jan 16, 2024
f23782f
Tidy loop go mod
zivkovicmilos Jan 16, 2024
655557b
Lowercase log format
zivkovicmilos Jan 16, 2024
c8b6d54
Move github.com/kr/pretty into indirect deps
zivkovicmilos Jan 22, 2024
db969ac
Move golang.org/x/exp into direct deps
zivkovicmilos Jan 22, 2024
a39674b
Remove duplicate defer
zivkovicmilos Jan 22, 2024
1c29d7c
Add import cleanup directive
zivkovicmilos Jan 22, 2024
a8e0dce
Move block to indirect imports; add mod linter
zivkovicmilos Jan 22, 2024
fe5f770
Remove leftover message from go.mods
zivkovicmilos Jan 22, 2024
4130b15
Add goimports CI
zivkovicmilos Jan 22, 2024
34e4087
Update gno.land/pkg/sdk/vm/keeper.go
zivkovicmilos Jan 22, 2024
d66b6f7
Update gno.land/pkg/sdk/vm/keeper.go
zivkovicmilos Jan 22, 2024
c3cd030
Merge branch 'master' into feat/log
zivkovicmilos Jan 22, 2024
795fe67
Make the linting gods happy
zivkovicmilos Jan 22, 2024
6779dc6
Merge branch 'master' into feat/log
zivkovicmilos Jan 23, 2024
01e4fd5
Add testing logger
zivkovicmilos Jan 23, 2024
6471c93
Tidy go mods
zivkovicmilos Jan 23, 2024
86ad349
Output the log to a dir
zivkovicmilos Jan 23, 2024
9e45196
Update workflows
zivkovicmilos Jan 23, 2024
301409a
fix: workflow debug env variable
gfanton Jan 23, 2024
821c01d
fix: fixup gnoland logs
gfanton Jan 23, 2024
09d3ec0
fix(ci): glob every log file into the artifact archive
gfanton Jan 23, 2024
de264d4
wip: test ci full logging
gfanton Jan 23, 2024
6b9230c
fix(log): replace slash by _ in log name to avoid sub-directory
gfanton Jan 23, 2024
27e2383
Enable debug artifacts
zivkovicmilos Jan 23, 2024
bac025e
Merge branch 'master' into feat/log
zivkovicmilos Jan 24, 2024
7eb92d2
Merge goimports format with 'fmt'
zivkovicmilos Jan 24, 2024
7720593
Update fmt CI
zivkovicmilos Jan 24, 2024
a8fe8d3
Update tidy workflow
zivkovicmilos Jan 24, 2024
9ab96d0
Simplify tidy workflows
zivkovicmilos Jan 24, 2024
89c7b62
Add basic base config verification
zivkovicmilos Jan 24, 2024
18727d8
Merge branch 'master' into feat/log
zivkovicmilos Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ linters:
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- gofumpt # Stricter gofmt
- unused # Checks Go code for unused constants, variables, functions and types
- gomodguard # Enforces an allow and block list for direct Go module dependencies

linters-settings:
gofmt:
Expand All @@ -59,6 +60,17 @@ linters-settings:
- opinionated
- performance
- style
gomodguard:
blocked:
modules:
- log/slog:
recommendations:
- golang.org/x/exp
reason: "the minimum go version for the monorepo is 1.20"
versions:
- go.uber.org/zap/exp:
version: "> 0.1.0"
reason: "this version of zap/exp is a requirement until we upgrade to go 1.21 (https://github.com/uber-go/zap/blob/master/exp/CHANGELOG.md)"

issues:
whole-files: true
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ jobs:
else
echo 'Succeeded.'
fi
imports:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x

- name: Install make
run: sudo apt-get install -y make

# prefill dependencies so that mod messages don't show up in make output
- name: Fetch dependencies
run: go mod download -modfile ./misc/devdeps/go.mod -x

- name: Check goimports
run: |
output="$(GOIMPORTS_FLAGS=-l make -s imports)"
if [ ! -z "$output" ]; then
echo "The following files are not properly formatted; run 'make imports' to format them."
echo "$output"
exit 1
else
echo 'Succeeded.'
fi
mod_tidy_check:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ fmt:
.PHONY: lint
lint:
$(rundep) github.com/golangci/golangci-lint/cmd/golangci-lint run --config .github/golangci.yml

.PHONY: imports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we merge in make fmt instead?

Copy link
Member Author

@zivkovicmilos zivkovicmilos Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged:

7eb92d2

Updated CI:
7720593

We should think about goimports linting for *.gno imports in the future

imports:
$(MAKE) --no-print-directory -C tm2 imports
$(MAKE) --no-print-directory -C gnovm imports
$(MAKE) --no-print-directory -C gno.land imports

.PHONY: tidy
tidy:
$(MAKE) --no-print-directory -C misc tidy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please double-check? I vaguely recall creating something similar, possibly only in the CI. Just ensure that there isn't already an existing solution for the same purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out we had not 1, but 2 tidy flows 🙂

Fixed:
9ab96d0 and a8fe8d3

5 changes: 5 additions & 0 deletions contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ replace github.com/gnolang/gno => ../..
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gnolang/gno v0.0.0-00010101000000-000000000000
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
golang.org/x/term v0.16.0
)

Expand Down Expand Up @@ -37,6 +39,7 @@ require (
github.com/jaekwon/testify v1.6.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.11 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
Expand All @@ -49,7 +52,9 @@ require (
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.opencensus.io v0.22.5 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap/exp v0.1.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
Expand Down
15 changes: 13 additions & 2 deletions contribs/gnodev/go.sum

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

16 changes: 8 additions & 8 deletions contribs/gnodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (
gnodev "github.com/gnolang/gno/contribs/gnodev/pkg/dev"
"github.com/gnolang/gno/contribs/gnodev/pkg/rawterm"
"github.com/gnolang/gno/gno.land/pkg/gnoweb"
"github.com/gnolang/gno/gno.land/pkg/log"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/commands"
tmlog "github.com/gnolang/gno/tm2/pkg/log"
osm "github.com/gnolang/gno/tm2/pkg/os"
"go.uber.org/zap/zapcore"
)

const (
Expand Down Expand Up @@ -61,6 +62,7 @@ additional specified paths.`,

cmd.Execute(context.Background(), os.Args[1:])
}

func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.webListenerAddr,
Expand Down Expand Up @@ -89,7 +91,6 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
defaultDevOptions.noWatch,
"do not watch for files change",
)

}

func execDev(cfg *devCfg, args []string, io commands.IO) error {
Expand Down Expand Up @@ -303,9 +304,9 @@ func setupRawTerm(io commands.IO) (rt *rawterm.RawTerm, restore func() error, er
func setupDevNode(ctx context.Context, rt *rawterm.RawTerm, pkgspath []string) (*gnodev.Node, error) {
nodeOut := rt.NamespacedWriter("Node")

logger := tmlog.NewTMLogger(nodeOut)
logger.SetLevel(tmlog.LevelError)
return gnodev.NewDevNode(ctx, logger, pkgspath)
zapLogger := log.NewZapConsoleLogger(nodeOut, zapcore.ErrorLevel)

return gnodev.NewDevNode(ctx, log.ZapLoggerToSlog(zapLogger), pkgspath)
}

// setupGnowebServer initializes and starts the Gnoweb server.
Expand All @@ -317,10 +318,9 @@ func serveGnoWebServer(l net.Listener, dnode *gnodev.Node, rt *rawterm.RawTerm)
webConfig.HelpChainID = dnode.Config().ChainID()
webConfig.HelpRemote = dnode.GetRemoteAddress()

loggerweb := tmlog.NewTMLogger(rt.NamespacedWriter("GnoWeb"))
loggerweb.SetLevel(tmlog.LevelDebug)
zapLogger := log.NewZapConsoleLogger(rt.NamespacedWriter("GnoWeb"), zapcore.DebugLevel)

app := gnoweb.MakeApp(loggerweb, webConfig)
app := gnoweb.MakeApp(log.ZapLoggerToSlog(zapLogger), webConfig)

server.ReadHeaderTimeout = 60 * time.Second
server.Handler = app.Router
Expand Down
14 changes: 7 additions & 7 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"github.com/gnolang/gno/tm2/pkg/bft/node"
bft "github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/log"
"github.com/gnolang/gno/tm2/pkg/std"
//backup "github.com/gnolang/tx-archive/backup/client"
//restore "github.com/gnolang/tx-archive/restore/client"
"golang.org/x/exp/slog"
// backup "github.com/gnolang/tx-archive/backup/client"
// restore "github.com/gnolang/tx-archive/restore/client"
)

const gnoDevChainID = "tendermint_test" // XXX: this is hardcoded and cannot be change bellow
Expand All @@ -27,7 +27,7 @@ const gnoDevChainID = "tendermint_test" // XXX: this is hardcoded and cannot be
type Node struct {
*node.Node

logger log.Logger
logger *slog.Logger
pkgs PkgsMap // path -> pkg
}

Expand All @@ -42,7 +42,7 @@ var (
}
)

func NewDevNode(ctx context.Context, logger log.Logger, pkgslist []string) (*Node, error) {
func NewDevNode(ctx context.Context, logger *slog.Logger, pkgslist []string) (*Node, error) {
mpkgs, err := newPkgsMap(pkgslist)
if err != nil {
return nil, fmt.Errorf("unable map pkgs list: %w", err)
Expand Down Expand Up @@ -102,7 +102,7 @@ func (d *Node) GetRemoteAddress() string {
return d.Node.Config().RPC.ListenAddress
}

// UpdatePackages updates the currently known packages. It will be taken into
// UpdatePackages updates the currently known packages. It will be taken into
// consideration in the next reload of the node.
func (d *Node) UpdatePackages(paths ...string) error {
for _, path := range paths {
Expand Down Expand Up @@ -403,7 +403,7 @@ func (pm PkgsMap) Load(creator bft.Address, fee std.Fee, deposit std.Coins) ([]s
return txs, nil
}

func newNode(logger log.Logger, genesis gnoland.GnoGenesisState) (*node.Node, error) {
func newNode(logger *slog.Logger, genesis gnoland.GnoGenesisState) (*node.Node, error) {
rootdir := gnoenv.RootDir()

nodeConfig := gnoland.NewDefaultInMemoryNodeConfig(rootdir)
Expand Down
4 changes: 1 addition & 3 deletions contribs/gnodev/pkg/rawterm/rawterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"golang.org/x/term"
)

var (
CRLF = []byte{'\r', '\n'}
)
var CRLF = []byte{'\r', '\n'}

// rawTerminal wraps an io.Writer, converting \n to \r\n
type RawTerm struct {
Expand Down
6 changes: 6 additions & 0 deletions contribs/gnokeykc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
Expand All @@ -30,21 +31,26 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/jaekwon/testify v1.6.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.11 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.opencensus.io v0.22.5 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 10 additions & 1 deletion contribs/gnokeykc/go.sum

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

Loading
Loading