Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
09d44247
Commit
09d44247
authored
May 22, 2018
by
kiel barry
Committed by
Péter Szilágyi
May 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: fixes for golint warnings (#16775)
parent
0fe47e98
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
19 deletions
+20
-19
README.md
log/README.md
+1
-1
doc.go
log/doc.go
+3
-3
format.go
log/format.go
+8
-8
handler.go
log/handler.go
+5
-5
logger.go
log/logger.go
+3
-2
No files found.
log/README.md
View file @
09d44247
...
@@ -45,7 +45,7 @@ srvlog.SetHandler(log.MultiHandler(
...
@@ -45,7 +45,7 @@ srvlog.SetHandler(log.MultiHandler(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
LogfmtFormat
()),
log
.
StreamHandler
(
os
.
Stderr
,
log
.
LogfmtFormat
()),
log
.
LvlFilterHandler
(
log
.
LvlFilterHandler
(
log
.
LvlError
,
log
.
LvlError
,
log
.
Must
.
FileHandler
(
"errors.json"
,
log
.
J
son
Format
()))))
log
.
Must
.
FileHandler
(
"errors.json"
,
log
.
J
SON
Format
()))))
```
```
Will result in output that looks like this:
Will result in output that looks like this:
...
...
log/doc.go
View file @
09d44247
...
@@ -86,7 +86,7 @@ from the rpc package in logfmt to standard out. The other prints records at Erro
...
@@ -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
or above in JSON formatted output to the file /var/log/service.json
handler := log.MultiHandler(
handler := log.MultiHandler(
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.J
son
Format())),
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler("/var/log/service.json", log.J
SON
Format())),
log.MatchFilterHandler("pkg", "app/rpc" log.StdoutHandler())
log.MatchFilterHandler("pkg", "app/rpc" log.StdoutHandler())
)
)
...
@@ -304,8 +304,8 @@ For all Handler functions which can return an error, there is a version of that
...
@@ -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
function which will return no error but panics on failure. They are all available
on the Must object. For example:
on the Must object. For example:
log.Must.FileHandler("/path", log.J
son
Format)
log.Must.FileHandler("/path", log.J
SON
Format)
log.Must.NetHandler("tcp", ":1234", log.J
son
Format)
log.Must.NetHandler("tcp", ":1234", log.J
SON
Format)
Inspiration and Credit
Inspiration and Credit
...
...
log/format.go
View file @
09d44247
...
@@ -196,16 +196,16 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
...
@@ -196,16 +196,16 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
buf
.
WriteByte
(
'\n'
)
buf
.
WriteByte
(
'\n'
)
}
}
// J
son
Format formats log records as JSON objects separated by newlines.
// J
SON
Format formats log records as JSON objects separated by newlines.
// It is the equivalent of J
son
FormatEx(false, true).
// It is the equivalent of J
SON
FormatEx(false, true).
func
J
son
Format
()
Format
{
func
J
SON
Format
()
Format
{
return
J
son
FormatEx
(
false
,
true
)
return
J
SON
FormatEx
(
false
,
true
)
}
}
// J
son
FormatEx formats log records as JSON objects. If pretty is true,
// J
SON
FormatEx formats log records as JSON objects. If pretty is true,
// records will be pretty-printed. If lineSeparated is true, records
// records will be pretty-printed. If lineSeparated is true, records
// will be logged with a new line between each record.
// will be logged with a new line between each record.
func
J
son
FormatEx
(
pretty
,
lineSeparated
bool
)
Format
{
func
J
SON
FormatEx
(
pretty
,
lineSeparated
bool
)
Format
{
jsonMarshal
:=
json
.
Marshal
jsonMarshal
:=
json
.
Marshal
if
pretty
{
if
pretty
{
jsonMarshal
=
func
(
v
interface
{})
([]
byte
,
error
)
{
jsonMarshal
=
func
(
v
interface
{})
([]
byte
,
error
)
{
...
@@ -225,7 +225,7 @@ func JsonFormatEx(pretty, lineSeparated bool) Format {
...
@@ -225,7 +225,7 @@ func JsonFormatEx(pretty, lineSeparated bool) Format {
if
!
ok
{
if
!
ok
{
props
[
errorKey
]
=
fmt
.
Sprintf
(
"%+v is not a string key"
,
r
.
Ctx
[
i
])
props
[
errorKey
]
=
fmt
.
Sprintf
(
"%+v is not a string key"
,
r
.
Ctx
[
i
])
}
}
props
[
k
]
=
formatJ
son
Value
(
r
.
Ctx
[
i
+
1
])
props
[
k
]
=
formatJ
SON
Value
(
r
.
Ctx
[
i
+
1
])
}
}
b
,
err
:=
jsonMarshal
(
props
)
b
,
err
:=
jsonMarshal
(
props
)
...
@@ -270,7 +270,7 @@ func formatShared(value interface{}) (result interface{}) {
...
@@ -270,7 +270,7 @@ func formatShared(value interface{}) (result interface{}) {
}
}
}
}
func
formatJ
son
Value
(
value
interface
{})
interface
{}
{
func
formatJ
SON
Value
(
value
interface
{})
interface
{}
{
value
=
formatShared
(
value
)
value
=
formatShared
(
value
)
switch
value
.
(
type
)
{
switch
value
.
(
type
)
{
case
int
,
int8
,
int16
,
int32
,
int64
,
float32
,
float64
,
uint
,
uint8
,
uint16
,
uint32
,
uint64
,
string
:
case
int
,
int8
,
int16
,
int32
,
int64
,
float32
,
float64
,
uint
,
uint8
,
uint16
,
uint32
,
uint64
,
string
:
...
...
log/handler.go
View file @
09d44247
...
@@ -11,8 +11,8 @@ import (
...
@@ -11,8 +11,8 @@ import (
"github.com/go-stack/stack"
"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.
// 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
// Handlers are composable, providing you great flexibility in combining
// them to achieve the logging structure that suits your applications.
// them to achieve the logging structure that suits your applications.
type
Handler
interface
{
type
Handler
interface
{
...
@@ -193,7 +193,7 @@ func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
...
@@ -193,7 +193,7 @@ func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
},
h
)
},
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
// This is useful for writing different types of log information
// to different locations. For example, to log to a file and
// to different locations. For example, to log to a file and
// standard error:
// standard error:
...
@@ -212,7 +212,7 @@ func MultiHandler(hs ...Handler) Handler {
...
@@ -212,7 +212,7 @@ 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
// specified, but will failover and write to the second handler if
// the first handler has failed, and so on for all handlers specified.
// 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
// For example you might want to log to a network socket, but failover
...
@@ -220,7 +220,7 @@ func MultiHandler(hs ...Handler) Handler {
...
@@ -220,7 +220,7 @@ func MultiHandler(hs ...Handler) Handler {
// standard out if the file write fails:
// standard out if the file write fails:
//
//
// log.FailoverHandler(
// log.FailoverHandler(
// log.Must.NetHandler("tcp", ":9090", log.J
son
Format()),
// log.Must.NetHandler("tcp", ":9090", log.J
SON
Format()),
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.Must.FileHandler("/var/log/app.log", log.LogfmtFormat()),
// log.StdoutHandler)
// log.StdoutHandler)
//
//
...
@@ -336,7 +336,7 @@ func DiscardHandler() Handler {
...
@@ -336,7 +336,7 @@ func DiscardHandler() Handler {
})
})
}
}
//
The Must objec
t provides the following Handler creation functions
//
Mus
t provides the following Handler creation functions
// which instead of returning an error parameter only return a Handler
// which instead of returning an error parameter only return a Handler
// and panic on failure: FileHandler, NetHandler, SyslogHandler, SyslogNetHandler
// and panic on failure: FileHandler, NetHandler, SyslogHandler, SyslogNetHandler
var
Must
muster
var
Must
muster
...
...
log/logger.go
View file @
09d44247
...
@@ -24,7 +24,7 @@ const (
...
@@ -24,7 +24,7 @@ const (
LvlTrace
LvlTrace
)
)
// Aligned returns a 5-character string containing the name of a Lvl.
// Aligned
String
returns a 5-character string containing the name of a Lvl.
func
(
l
Lvl
)
AlignedString
()
string
{
func
(
l
Lvl
)
AlignedString
()
string
{
switch
l
{
switch
l
{
case
LvlTrace
:
case
LvlTrace
:
...
@@ -64,7 +64,7 @@ func (l Lvl) String() string {
...
@@ -64,7 +64,7 @@ func (l Lvl) String() string {
}
}
}
}
//
R
eturns the appropriate Lvl from a string name.
//
LvlFromString r
eturns the appropriate Lvl from a string name.
// Useful for parsing command line args and configuration files.
// Useful for parsing command line args and configuration files.
func
LvlFromString
(
lvlString
string
)
(
Lvl
,
error
)
{
func
LvlFromString
(
lvlString
string
)
(
Lvl
,
error
)
{
switch
lvlString
{
switch
lvlString
{
...
@@ -95,6 +95,7 @@ type Record struct {
...
@@ -95,6 +95,7 @@ type Record struct {
KeyNames
RecordKeyNames
KeyNames
RecordKeyNames
}
}
// RecordKeyNames gets stored in a Record when the write function is executed.
type
RecordKeyNames
struct
{
type
RecordKeyNames
struct
{
Time
string
Time
string
Msg
string
Msg
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment