Skip to content

Commit

Permalink
log: fixes for golint warnings (ethereum#16775)
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbarry authored and karalabe committed May 22, 2018
1 parent 0fe47e9 commit 09d4424
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ srvlog.SetHandler(log.MultiHandler(
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler("errors.json", log.JsonFormat()))))
log.Must.FileHandler("errors.json", log.JSONFormat()))))
```

Will result in output that looks like this:
Expand Down
6 changes: 3 additions & 3 deletions log/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ from the rpc package in logfmt to standard out. The other prints records at Erro
or above in JSON formatted output to the file /var/log/service.json
handler := log.MultiHandler(
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.JsonFormat())),
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.JSONFormat())),
log.MatchFilterHandler("pkg", "app/rpc" log.StdoutHandler())
)
Expand Down Expand Up @@ -304,8 +304,8 @@ For all Handler functions which can return an error, there is a version of that
function which will return no error but panics on failure. They are all available
on the Must object. For example:
log.Must.FileHandler("/path", log.JsonFormat)
log.Must.NetHandler("tcp", ":1234", log.JsonFormat)
log.Must.FileHandler("/path", log.JSONFormat)
log.Must.NetHandler("tcp", ":1234", log.JSONFormat)
Inspiration and Credit
Expand Down
16 changes: 8 additions & 8 deletions log/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
buf.WriteByte('\n')
}

// JsonFormat formats log records as JSON objects separated by newlines.
// It is the equivalent of JsonFormatEx(false, true).
func JsonFormat() Format {
return JsonFormatEx(false, true)
// JSONFormat formats log records as JSON objects separated by newlines.
// It is the equivalent of JSONFormatEx(false, true).
func JSONFormat() Format {
return JSONFormatEx(false, true)
}

// JsonFormatEx formats log records as JSON objects. If pretty is true,
// JSONFormatEx formats log records as JSON objects. If pretty is true,
// records will be pretty-printed. If lineSeparated is true, records
// will be logged with a new line between each record.
func JsonFormatEx(pretty, lineSeparated bool) Format {
func JSONFormatEx(pretty, lineSeparated bool) Format {
jsonMarshal := json.Marshal
if pretty {
jsonMarshal = func(v interface{}) ([]byte, error) {
Expand All @@ -225,7 +225,7 @@ func JsonFormatEx(pretty, lineSeparated bool) Format {
if !ok {
props[errorKey] = fmt.Sprintf("%+v is not a string key", r.Ctx[i])
}
props[k] = formatJsonValue(r.Ctx[i+1])
props[k] = formatJSONValue(r.Ctx[i+1])
}

b, err := jsonMarshal(props)
Expand Down Expand Up @@ -270,7 +270,7 @@ func formatShared(value interface{}) (result interface{}) {
}
}

func formatJsonValue(value interface{}) interface{} {
func formatJSONValue(value interface{}) interface{} {
value = formatShared(value)
switch value.(type) {
case int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64, string:
Expand Down
10 changes: 5 additions & 5 deletions log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/go-stack/stack"
)

// Handler defines where and how log records are written.
// A Logger prints its log records by writing to a Handler.
// The Handler interface defines where and how log records are written.
// Handlers are composable, providing you great flexibility in combining
// them to achieve the logging structure that suits your applications.
type Handler interface {
Expand Down Expand Up @@ -193,7 +193,7 @@ func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
}, h)
}

// A MultiHandler dispatches any write to each of its handlers.
// MultiHandler dispatches any write to each of its handlers.
// This is useful for writing different types of log information
// to different locations. For example, to log to a file and
// standard error:
Expand All @@ -212,15 +212,15 @@ func MultiHandler(hs ...Handler) Handler {
})
}

// A FailoverHandler writes all log records to the first handler
// FailoverHandler writes all log records to the first handler
// specified, but will failover and write to the second handler if
// the first handler has failed, and so on for all handlers specified.
// For example you might want to log to a network socket, but failover
// 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.NetHandler("tcp", ":9090", log.JSONFormat()),
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StdoutHandler)
//
Expand Down Expand Up @@ -336,7 +336,7 @@ func DiscardHandler() Handler {
})
}

// The Must object provides the following Handler creation functions
// Must provides the following Handler creation functions
// which instead of returning an error parameter only return a Handler
// and panic on failure: FileHandler, NetHandler, SyslogHandler, SyslogNetHandler
var Must muster
Expand Down
5 changes: 3 additions & 2 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
LvlTrace
)

// Aligned returns a 5-character string containing the name of a Lvl.
// AlignedString returns a 5-character string containing the name of a Lvl.
func (l Lvl) AlignedString() string {
switch l {
case LvlTrace:
Expand Down Expand Up @@ -64,7 +64,7 @@ func (l Lvl) String() string {
}
}

// Returns the appropriate Lvl from a string name.
// LvlFromString returns the appropriate Lvl from a string name.
// Useful for parsing command line args and configuration files.
func LvlFromString(lvlString string) (Lvl, error) {
switch lvlString {
Expand Down Expand Up @@ -95,6 +95,7 @@ type Record struct {
KeyNames RecordKeyNames
}

// RecordKeyNames gets stored in a Record when the write function is executed.
type RecordKeyNames struct {
Time string
Msg string
Expand Down

0 comments on commit 09d4424

Please sign in to comment.