Skip to content

Commit

Permalink
log: fix typos in comments (ethereum#21118)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Nov 12, 2024
1 parent c95cd72 commit 273e114
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion log/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This will output a log line that includes the path context that is attached to t
Handlers
The Handler interface defines where log lines are printed to and how they are formated. Handler is a
The Handler interface defines where log lines are printed to and how they are formatted. Handler is a
single interface that is inspired by net/http's handler interface:
type Handler interface {
Expand Down
4 changes: 2 additions & 2 deletions log/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func PrintOrigins(print bool) {
var locationEnabled uint32

// locationLength is the maxmimum path length encountered, which all logs are
// padded to to aid in alignment.
// padded to aid in alignment.
var locationLength uint32

// fieldPadding is a global map with maximum field value lengths seen until now
Expand Down Expand Up @@ -78,7 +78,7 @@ type TerminalStringer interface {
// a terminal with color-coded level output and terser human friendly timestamp.
// This format should only be used for interactive programs or while developing.
//
// [TIME] [LEVEL] MESAGE key=value key=value ...
// [TIME] [LEVEL] MESSAGE key=value key=value ...
//
// Example:
//
Expand Down
40 changes: 18 additions & 22 deletions log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func formatCall(format string, c stack.Call) string {
}

// CallerStackHandler returns a Handler that adds a stack trace to the context
// with key "stack". The stack trace is formated as a space separated list of
// with key "stack". The stack trace is formatted as a space separated list of
// call sites inside matching []'s. The most recent call site is listed first.
// Each call site is formatted according to format. See the documentation of
// package github.com/go-stack/stack for the list of supported formats.
Expand All @@ -135,15 +135,14 @@ func CallerStackHandler(format string, h Handler) Handler {
// wrapped Handler if the given function evaluates true. For example,
// to only log records where the 'err' key is not nil:
//
// logger.SetHandler(FilterHandler(func(r *Record) bool {
// for i := 0; i < len(r.Ctx); i += 2 {
// if r.Ctx[i] == "err" {
// return r.Ctx[i+1] != nil
// }
// }
// return false
// }, h))
//
// logger.SetHandler(FilterHandler(func(r *Record) bool {
// for i := 0; i < len(r.Ctx); i += 2 {
// if r.Ctx[i] == "err" {
// return r.Ctx[i+1] != nil
// }
// }
// return false
// }, h))
func FilterHandler(fn func(r *Record) bool, h Handler) Handler {
return FuncHandler(func(r *Record) error {
if fn(r) {
Expand All @@ -158,8 +157,7 @@ func FilterHandler(fn func(r *Record) bool, h Handler) Handler {
// context matches the value. For example, to only log records
// from your ui package:
//
// log.MatchFilterHandler("pkg", "app/ui", log.StdoutHandler)
//
// log.MatchFilterHandler("pkg", "app/ui", log.StdoutHandler)
func MatchFilterHandler(key string, value interface{}, h Handler) Handler {
return FilterHandler(func(r *Record) (pass bool) {
switch key {
Expand All @@ -185,8 +183,7 @@ func MatchFilterHandler(key string, value interface{}, h Handler) Handler {
// level to the wrapped Handler. For example, to only
// log Error/Crit records:
//
// log.LvlFilterHandler(log.LvlError, log.StdoutHandler)
//
// log.LvlFilterHandler(log.LvlError, log.StdoutHandler)
func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
return FilterHandler(func(r *Record) (pass bool) {
return r.Lvl <= maxLvl
Expand All @@ -198,10 +195,9 @@ func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
// to different locations. For example, to log to a file and
// standard error:
//
// log.MultiHandler(
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StderrHandler)
//
// log.MultiHandler(
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StderrHandler)
func MultiHandler(hs ...Handler) Handler {
return FuncHandler(func(r *Record) error {
for _, h := range hs {
Expand All @@ -219,10 +215,10 @@ func MultiHandler(hs ...Handler) Handler {
// to writing to a file if the network fails, and then to
// standard out if the file write fails:
//
// log.FailoverHandler(
// log.Must.NetHandler("tcp", ":9090", log.JsonFormat()),
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StdoutHandler)
// log.FailoverHandler(
// log.Must.NetHandler("tcp", ":9090", log.JsonFormat()),
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StdoutHandler)
//
// All writes that do not go to the first handler will add context with keys of
// the form "failover_err_{idx}" which explain the error encountered while
Expand Down

0 comments on commit 273e114

Please sign in to comment.