Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zap logger and access log interceptor #944

Merged
merged 9 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/vald/values.schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion charts/vald/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ defaults:
# @schema {"name": "defaults.server_config.servers.grpc.server.grpc.header_table_size", "type": "integer"}
# defaults.server_config.servers.grpc.server.grpc.header_table_size -- gRPC server header table size
header_table_size: 0
# @schema {"name": "defaults.server_config.servers.grpc.server.grpc.interceptors", "type": "array", "items": {"type": "string", "enum": ["RecoverInterceptor", "TracePayloadInterceptor"]}}
# @schema {"name": "defaults.server_config.servers.grpc.server.grpc.interceptors", "type": "array", "items": {"type": "string", "enum": ["RecoverInterceptor", "AccessLogInterceptor", "TracePayloadInterceptor"]}}
# defaults.server_config.servers.grpc.server.grpc.interceptors -- gRPC server interceptors
interceptors:
- "RecoverInterceptor"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
go.opencensus.io v0.22.5
go.uber.org/automaxprocs v1.3.0
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down
10 changes: 5 additions & 5 deletions internal/log/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
Unknown Format = iota
RAW
JSON
LTSV
// LTSV
)

func (f Format) String() string {
Expand All @@ -33,8 +33,8 @@ func (f Format) String() string {
return "raw"
case JSON:
return "json"
case LTSV:
return "ltsv"
// case LTSV:
// return "ltsv"
}
return "unknown"
}
Expand All @@ -45,8 +45,8 @@ func Atof(str string) Format {
return RAW
case "json":
return JSON
case "ltsv":
return LTSV
// case "ltsv":
// return LTSV
}
return Unknown
}
44 changes: 22 additions & 22 deletions internal/log/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func TestFormat_String(t *testing.T) {
},
},

{
name: "returns ltsv when f is LTSV",
f: LTSV,
want: want{
want: "ltsv",
},
},
// {
// name: "returns ltsv when f is LTSV",
// f: LTSV,
// want: want{
// want: "ltsv",
// },
// },

{
name: "returns unknown when f is 100",
Expand Down Expand Up @@ -148,21 +148,21 @@ func TestAtof(t *testing.T) {
},
},

{
name: "returns LTSV when str is `ltsv`",
str: "ltsv",
want: want{
want: LTSV,
},
},

{
name: "returns LTSV when str is `LTSv`",
str: "LTSv",
want: want{
want: LTSV,
},
},
// {
// name: "returns LTSV when str is `ltsv`",
// str: "ltsv",
// want: want{
// want: LTSV,
// },
// },
//
// {
// name: "returns LTSV when str is `LTSv`",
// str: "LTSv",
// want: want{
// want: LTSV,
// },
// },

{
name: "returns Unknown when str is `Vald`",
Expand Down
28 changes: 28 additions & 0 deletions internal/log/glg/glg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
"github.com/vdaas/vald/internal/log/retry"
)

const (
detailsFormat = "%s\tdetails: %#v"
)

type logger struct {
format format.Format
level level.Level
Expand Down Expand Up @@ -73,6 +77,10 @@ func (l *logger) setLogFormat(fmt format.Format) *logger {
return l
}

func (l *logger) Close() error {
return nil
}

func (l *logger) Info(vals ...interface{}) {
l.retry.Out(l.glg.Info, vals...)
}
Expand All @@ -81,6 +89,10 @@ func (l *logger) Infof(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Infof, format, vals...)
}

func (l *logger) Infod(msg string, details ...interface{}) {
l.Infof(detailsFormat, msg, details)
}

func (l *logger) Debug(vals ...interface{}) {
l.retry.Out(l.glg.Debug, vals...)
}
Expand All @@ -89,6 +101,10 @@ func (l *logger) Debugf(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Debugf, format, vals...)
}

func (l *logger) Debugd(msg string, details ...interface{}) {
l.Debugf(detailsFormat, msg, details)
}

func (l *logger) Warn(vals ...interface{}) {
l.retry.Out(l.glg.Warn, vals...)
}
Expand All @@ -97,6 +113,10 @@ func (l *logger) Warnf(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Warnf, format, vals...)
}

func (l *logger) Warnd(msg string, details ...interface{}) {
l.Warnf(detailsFormat, msg, details)
}

func (l *logger) Error(vals ...interface{}) {
l.retry.Out(l.glg.Error, vals...)
}
Expand All @@ -105,10 +125,18 @@ func (l *logger) Errorf(format string, vals ...interface{}) {
l.retry.Outf(l.glg.Errorf, format, vals...)
}

func (l *logger) Errord(msg string, details ...interface{}) {
l.Errorf(detailsFormat, msg, details)
}

func (l *logger) Fatal(vals ...interface{}) {
l.glg.Fatal(vals...)
}

func (l *logger) Fatalf(format string, vals ...interface{}) {
l.glg.Fatalf(format, vals...)
}

func (l *logger) Fatald(msg string, details ...interface{}) {
l.Fatalf(detailsFormat, msg, details)
}
Loading