Skip to content

Commit 09d4424

Browse files
kielbarrykaralabe
authored andcommitted
log: fixes for golint warnings (#16775)
1 parent 0fe47e9 commit 09d4424

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

log/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ srvlog.SetHandler(log.MultiHandler(
4545
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
4646
log.LvlFilterHandler(
4747
log.LvlError,
48-
log.Must.FileHandler("errors.json", log.JsonFormat()))))
48+
log.Must.FileHandler("errors.json", log.JSONFormat()))))
4949
```
5050

5151
Will result in output that looks like this:

log/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ from the rpc package in logfmt to standard out. The other prints records at Erro
8686
or above in JSON formatted output to the file /var/log/service.json
8787
8888
handler := log.MultiHandler(
89-
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.JsonFormat())),
89+
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.JSONFormat())),
9090
log.MatchFilterHandler("pkg", "app/rpc" log.StdoutHandler())
9191
)
9292
@@ -304,8 +304,8 @@ For all Handler functions which can return an error, there is a version of that
304304
function which will return no error but panics on failure. They are all available
305305
on the Must object. For example:
306306
307-
log.Must.FileHandler("/path", log.JsonFormat)
308-
log.Must.NetHandler("tcp", ":1234", log.JsonFormat)
307+
log.Must.FileHandler("/path", log.JSONFormat)
308+
log.Must.NetHandler("tcp", ":1234", log.JSONFormat)
309309
310310
Inspiration and Credit
311311

log/format.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
196196
buf.WriteByte('\n')
197197
}
198198

199-
// JsonFormat formats log records as JSON objects separated by newlines.
200-
// It is the equivalent of JsonFormatEx(false, true).
201-
func JsonFormat() Format {
202-
return JsonFormatEx(false, true)
199+
// JSONFormat formats log records as JSON objects separated by newlines.
200+
// It is the equivalent of JSONFormatEx(false, true).
201+
func JSONFormat() Format {
202+
return JSONFormatEx(false, true)
203203
}
204204

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

231231
b, err := jsonMarshal(props)
@@ -270,7 +270,7 @@ func formatShared(value interface{}) (result interface{}) {
270270
}
271271
}
272272

273-
func formatJsonValue(value interface{}) interface{} {
273+
func formatJSONValue(value interface{}) interface{} {
274274
value = formatShared(value)
275275
switch value.(type) {
276276
case int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64, string:

log/handler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/go-stack/stack"
1212
)
1313

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

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

215-
// A FailoverHandler writes all log records to the first handler
215+
// FailoverHandler writes all log records to the first handler
216216
// specified, but will failover and write to the second handler if
217217
// the first handler has failed, and so on for all handlers specified.
218218
// For example you might want to log to a network socket, but failover
219219
// to writing to a file if the network fails, and then to
220220
// standard out if the file write fails:
221221
//
222222
// log.FailoverHandler(
223-
// log.Must.NetHandler("tcp", ":9090", log.JsonFormat()),
223+
// log.Must.NetHandler("tcp", ":9090", log.JSONFormat()),
224224
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
225225
// log.StdoutHandler)
226226
//
@@ -336,7 +336,7 @@ func DiscardHandler() Handler {
336336
})
337337
}
338338

339-
// The Must object provides the following Handler creation functions
339+
// Must provides the following Handler creation functions
340340
// which instead of returning an error parameter only return a Handler
341341
// and panic on failure: FileHandler, NetHandler, SyslogHandler, SyslogNetHandler
342342
var Must muster

log/logger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
LvlTrace
2525
)
2626

27-
// Aligned returns a 5-character string containing the name of a Lvl.
27+
// AlignedString returns a 5-character string containing the name of a Lvl.
2828
func (l Lvl) AlignedString() string {
2929
switch l {
3030
case LvlTrace:
@@ -64,7 +64,7 @@ func (l Lvl) String() string {
6464
}
6565
}
6666

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

98+
// RecordKeyNames gets stored in a Record when the write function is executed.
9899
type RecordKeyNames struct {
99100
Time string
100101
Msg string

0 commit comments

Comments
 (0)