good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
09d44247
Commit
09d44247
authored
May 22, 2018
by
kiel barry
Committed by
Péter Szilágyi
May 22, 2018
Browse files
Options
Downloads
Patches
Plain Diff
log: fixes for golint warnings (#16775)
parent
0fe47e98
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
log/README.md
+1
-1
1 addition, 1 deletion
log/README.md
log/doc.go
+3
-3
3 additions, 3 deletions
log/doc.go
log/format.go
+8
-8
8 additions, 8 deletions
log/format.go
log/handler.go
+5
-5
5 additions, 5 deletions
log/handler.go
log/logger.go
+3
-2
3 additions, 2 deletions
log/logger.go
with
20 additions
and
19 deletions
log/README.md
+
1
−
1
View file @
09d44247
...
...
@@ -45,7 +45,7 @@ srvlog.SetHandler(log.MultiHandler(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
LogfmtFormat
()),
log
.
LvlFilterHandler
(
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:
...
...
This diff is collapsed.
Click to expand it.
log/doc.go
+
3
−
3
View file @
09d44247
...
...
@@ -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.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())
)
...
...
@@ -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.J
son
Format)
log.Must.NetHandler("tcp", ":1234", log.J
son
Format)
log.Must.FileHandler("/path", log.J
SON
Format)
log.Must.NetHandler("tcp", ":1234", log.J
SON
Format)
Inspiration and Credit
...
...
This diff is collapsed.
Click to expand it.
log/format.go
+
8
−
8
View file @
09d44247
...
...
@@ -196,16 +196,16 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
buf
.
WriteByte
(
'\n'
)
}
// J
son
Format formats log records as JSON objects separated by newlines.
// It is the equivalent of J
son
FormatEx(false, true).
func
J
son
Format
()
Format
{
return
J
son
FormatEx
(
false
,
true
)
// J
SON
Format formats log records as JSON objects separated by newlines.
// It is the equivalent of J
SON
FormatEx(false, true).
func
J
SON
Format
()
Format
{
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
// 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
if
pretty
{
jsonMarshal
=
func
(
v
interface
{})
([]
byte
,
error
)
{
...
...
@@ -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
]
=
formatJ
son
Value
(
r
.
Ctx
[
i
+
1
])
props
[
k
]
=
formatJ
SON
Value
(
r
.
Ctx
[
i
+
1
])
}
b
,
err
:=
jsonMarshal
(
props
)
...
...
@@ -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
)
switch
value
.
(
type
)
{
case
int
,
int8
,
int16
,
int32
,
int64
,
float32
,
float64
,
uint
,
uint8
,
uint16
,
uint32
,
uint64
,
string
:
...
...
This diff is collapsed.
Click to expand it.
log/handler.go
+
5
−
5
View file @
09d44247
...
...
@@ -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
{
...
...
@@ -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:
...
...
@@ -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
// 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
...
...
@@ -220,7 +220,7 @@ func MultiHandler(hs ...Handler) Handler {
// standard out if the file write fails:
//
// 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.StdoutHandler)
//
...
...
@@ -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
// and panic on failure: FileHandler, NetHandler, SyslogHandler, SyslogNetHandler
var
Must
muster
...
...
This diff is collapsed.
Click to expand it.
log/logger.go
+
3
−
2
View file @
09d44247
...
...
@@ -24,7 +24,7 @@ const (
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
{
switch
l
{
case
LvlTrace
:
...
...
@@ -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.
func
LvlFromString
(
lvlString
string
)
(
Lvl
,
error
)
{
switch
lvlString
{
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment