Skip to content

Commit

Permalink
feat: standardize logging (#1302)
Browse files Browse the repository at this point in the history
## Description

This PR introduces log standardization across the codebase, to utilize
the `slog.Logger`.

Since the gno repo currently utilizes `go1.20` as the minimum version,
this PR utilizes the `golang.org/x/exp/log` package.

Additionally, this PR removes log level management from the TM2 config,
and instead moves it into the start command.

Closes #999 

Thank you @gfanton for helping out with zap and simplifying the API 🙏 
Special shoutout to @moul's
[zapconfig](https://github.com/moul/zapconfig/tree/master), for being an
inspiration on zap setup.

**BREAKING CHANGE**:
- the `tm2/log` logger interface has been removed, everything has been
swapped to `*slog.Logger`

Example of different log levels:

![cast](https://github.com/gnolang/gno/assets/16712663/2288ad98-7f72-4f05-b749-827b815b7f16)


<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: gfanton <[email protected]>
Co-authored-by: gfanton <[email protected]>
Co-authored-by: Manfred Touron <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent 42d270a commit da35d3c
Show file tree
Hide file tree
Showing 113 changed files with 1,139 additions and 839 deletions.
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
9 changes: 9 additions & 0 deletions .github/workflows/db-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ jobs:
wget http://ftp.us.debian.org/debian/pool/main/l/leveldb/libleveldb-dev_1.22-3_amd64.deb
sudo dpkg -i *.deb
- name: Set environment variables for debug mode
if: env.ACTIONS_STEP_DEBUG == 'true'
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
# test ./pkgs/db
- name: test ./tm2/pkg/db
run: go test -tags ${{ matrix.tags }} ./tm2/pkg/db/...
16 changes: 6 additions & 10 deletions .github/workflows/dependabot-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ jobs:
go-version: 1.21.x

- name: Tidy all Go mods
env:
VERIFY_MOD_SUMS: false
run: |
set -e
# Find all go.mod files
gomods=$(find . -type f -name go.mod)
# Tidy each go.mod file
for modfile in $gomods; do
dir=$(dirname "$modfile")
# Ensure Make is installed
make --version
# Run go mod tidy in the directory
(cd "$dir" && go mod tidy -v) || exit 1
done
# Run the tidy target
make tidy
- name: Commit changes, if any
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goversion }}
- name: Set environment variables for debug mode
if: env.ACTIONS_STEP_DEBUG == 'true'
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno test --verbose ./examples/...
lint:
Expand Down
25 changes: 16 additions & 9 deletions .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,39 @@ jobs:
- _test.gnoland
- _test.gnokey
- _test.pkgs
- _test.gnoweb
- _test.gnoweb
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goversion }}
- name: Set environment variables for debug mode
if: ${{ runner.debug == 1 }}
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs-go${{ matrix.goversion }}-${{ matrix.args }}
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- name: test
working-directory: gno.land
run: |
export GOPATH=$HOME/go
export GOTEST_FLAGS="-v -p 1 -timeout=30m -coverprofile=coverage.out -covermode=atomic"
export LOG_DIR="${{ runner.temp }}/logs/test-${{ matrix.goversion }}-gnoland"
make ${{ matrix.args }}
- name: Upload Test Log
if: always()
uses: actions/upload-artifact@v3
with:
name: logs-test-gnoland-go${{ matrix.goversion }}
path: ${{ runner.temp }}/logs/**/*.log
- uses: actions/upload-artifact@v3
if: ${{ runner.os == 'Linux' && matrix.goversion == '1.21.x' }}
with:
name: ${{runner.os}}-coverage-gnoland-${{ matrix.args}}-${{matrix.goversion}}
path: ./gno.land/coverage.out
- name: Upload Debug Logs
uses: actions/upload-artifact@v3
if: ${{ always() && runner.debug == 1 }}
with:
name: logs-test-go${{ matrix.goversion }}-${{ matrix.args }}
path: ${{ env.LOG_PATH_DIR }}/**/*

upload-coverage:
needs: test
Expand All @@ -99,7 +106,7 @@ jobs:
uses: codecov/codecov-action@v3
with:
directory: ${{ runner.temp }}/coverage
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

docker-integration:
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/gnovm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goversion }}
- name: Set environment variables for debug mode
if: ${{ runner.debug == 1 }}
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs-go${{ matrix.goversion }}-${{ matrix.args }}
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- name: test
working-directory: gnovm
env:
Expand All @@ -92,6 +100,12 @@ jobs:
with:
name: ${{runner.os}}-coverage-gnovm-${{ matrix.args}}-${{matrix.goversion}}
path: ${{ env.COVERAGE_DIR }}
- name: Upload Debug Logs
uses: actions/upload-artifact@v3
if: ${{ always() && runner.debug == 1 }}
with:
name: logs-test-go${{ matrix.goversion }}-${{ matrix.args }}
path: ${{ env.LOG_PATH_DIR }}/**/*

upload-coverage:
needs: test
Expand Down Expand Up @@ -129,6 +143,6 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: ${{ env.COVERAGE_PROFILE }}
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

33 changes: 13 additions & 20 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:

# inspired by:
# https://github.com/Jerome1337/gofmt-action/blob/d5eabd189843f1d568286a54578159978b7c0fb1/entrypoint.sh
- name: Check gofumpt
- name: Check gofumpt / goimports
run: |
output="$(GOFMT_FLAGS=-l make -s fmt)"
output="$(GOFMT_FLAGS=-l GOIMPORTS_FLAGS=-l make -s fmt)"
if [ ! -z "$output" ]; then
echo "The following files are not properly formatted; run 'make fmt' to format them."
echo "The following files are not properly formatted; run 'make fmt imports' to format them."
echo "$output"
exit 1
else
Expand All @@ -70,22 +70,15 @@ jobs:
with:
go-version: 1.21.x

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

- name: Check go.mods
env:
VERIFY_MOD_SUMS: true
run: |
set -xe
# Find all go.mod files
gomods=$(find . -type f -name go.mod)
# Calculate sums for all go.mod files
sums=$(sha256sum $gomods)
# Iterate over each go.mod file
for modfile in $gomods; do
dir=$(dirname "$modfile")
# Run go mod tidy in the directory
(cd "$dir" && go mod tidy -v) || exit 1
done
# Verify the sums
echo "$sums" | sha256sum -c
# Ensure Make is installed
make --version
# Run the tidy target
make tidy
9 changes: 9 additions & 0 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ jobs:
with:
go-version: ${{ matrix.goversion }}

- name: Set environment variables for debug mode
if: env.ACTIONS_STEP_DEBUG == 'true'
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- name: Test
working-directory: misc
run: |
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/tm2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
working-directory: tm2
run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go install ${{ matrix.program }}


test:
strategy:
fail-fast: false
Expand All @@ -61,6 +62,14 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goversion }}
- name: Set environment variables for debug mode
if: ${{ runner.debug == 1 }}
run: |
export LOG_PATH_DIR=${{ runner.temp }}/logs-go${{ matrix.goversion }}-${{ matrix.args }}
mkdir -p $LOG_PATH_DIR
echo "LOG_LEVEL=debug" >> $GITHUB_ENV
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- name: test
working-directory: tm2
run: |
Expand All @@ -73,6 +82,12 @@ jobs:
with:
name: ${{runner.os}}-coverage-tm2-${{ matrix.args}}-${{matrix.goversion}}
path: ./tm2/coverage.out
- name: Upload Debug Logs
uses: actions/upload-artifact@v3
if: ${{ always() && runner.debug == 1 }}
with:
name: logs-test-go${{ matrix.goversion }}-${{ matrix.args }}
path: ${{ env.LOG_PATH_DIR }}/**/*

upload-coverage:
needs: test
Expand All @@ -86,6 +101,6 @@ jobs:
uses: codecov/codecov-action@v3
with:
directory: ${{ runner.temp }}/coverage
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: ${{ github.repository == 'gnolang/gno' }}

10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ test.docker:

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

.PHONY: lint
lint:
$(rundep) github.com/golangci/golangci-lint/cmd/golangci-lint run --config .github/golangci.yml

.PHONY: tidy
tidy:
$(MAKE) --no-print-directory -C misc tidy
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 @@ -38,6 +40,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 @@ -50,7 +53,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.

Loading

0 comments on commit da35d3c

Please sign in to comment.