forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What does this PR do? This PR proposes to revamp our `log` package. The idea is to have more information in the logs without having to add them manually on each log line. This is accomplished by providing a way to get **child loggers** derived from the **root** one: - **Every function** that needs to inject new fields in the logs can do so by calling `WithFields` on the current logger. - **This returns** a new child logger that will print the provided fields on every log line (within the function scope) in addition to the parent logger fields. ### Example ```go // use root logger log.Debug("This is a debug log line from the root logger") // derive a child logger from the root one, with additional fields childLog := log.WithFields("txHash", "0xbanana", "chainId", 42) // these two log lines will be decorated with the `txHash` and `chainId` fields childLog.Debug("This is a debug log line") childLog.Debug("This is another debug log line") // derive a child logger from the previous child, adding another field grandChildLog := childLog.WithFields("proverId", "prover123") // this log line will be decorated with the `txHash`, `chainId` and `proverId` fields grandChildLog.Debug("This is a debug log line from the granchild logger") // derive another child logger from the root one, with another field childLog2 := log.WithFields("batchNum": 8) // this line will only have the `batchNum` field childLog2.Debug("This is a debug log line from the second child logger") ``` **NOTE:** here 2 default fields have been added to **every** log line: `version` and `pid`. They are purely demonstrative and can be removed/replaced with better ones. Other logs have been decorated with fields inside `jsonrpc` and `metrics` package. The idea is to gradually start using the feature while developing. **ENCODING** Now the encoding of the logs can be specified in the config file choosing between `console` and `json`. The default value is `console`, but `json` can be used in a deployed environment for better logs ingestion. ### Bonus The log message on startup has been polished a bit: ```sh Version: v0.0.1-RC1-5-g8538ace Git revision: 8538ace Git branch: feature/revamp-logs Go version: go1.17.13 Built: Fri, 02 Dec 2022 16:47:58 +0000 OS/Arch: linux/amd64 ``` The env var to pass the commit hash is not needed any more, instead it is sourced from the `Makefile` through a linker flag.
- Loading branch information
Showing
27 changed files
with
322 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func versionCmd(*cli.Context) error { | ||
fmt.Printf("Version = \"%v\"\n", version) | ||
fmt.Printf("Build = \"%v\"\n", commit) | ||
fmt.Printf("Date = \"%v\"\n", date) | ||
zkevm.PrintVersion(os.Stdout) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.