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

docs: add logging.InjectFields usage description #540

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
4d4c8f9
Initial change for v2.
bwplotka Feb 29, 2020
dfb47b3
Addressed comments.
bwplotka Mar 5, 2020
ce741ac
Merge pull request #276 from grpc-ecosystem/v2-init
bwplotka Mar 5, 2020
41f1280
Updated README with note that it's under development.
bwplotka Mar 5, 2020
542dcc3
Merge pull request #278 from grpc-ecosystem/update-readme
bwplotka Mar 5, 2020
eb2c8a6
Fix typo in field extractor (splices -> slices) (#287) (#289)
bvwells Apr 29, 2020
818c8cf
Moved imports to v2; Moved to Go 1.14.2 (#290)
bwplotka May 1, 2020
55554ba
Formatted code; Added goimports to Makefile, Renamed pb_testproto to …
bwplotka May 1, 2020
2017e41
Fixed providers go modules, examples and consistency. (#292)
bwplotka May 2, 2020
a0e7c73
added example for AuthFuncOverride (#294)
tegk May 12, 2020
4664c92
Added some description of the Makefile in the contributing.md (#298)
yashrsharma44 Jun 3, 2020
e482ad4
Add support for the zerolog logging provider (#299)
irridia Jun 3, 2020
6e2c2ac
proto: fix gogoproto import (#302)
johanbrandhorst Jun 4, 2020
b99e582
Retry dial and connection errors for grpc stream. (#308)
kartlee Jun 17, 2020
880c174
Moved to GH actions; Added lint; Added issue/PR templates. (#296)
bwplotka Jun 18, 2020
61761eb
inline localhost certificate into go file (#318)
bmon Jul 16, 2020
f2e4dcb
Update streaming interceptor example (#322)
G07cha Jul 24, 2020
d07eb4f
Do not stop retrying based on earlier good message from the stream (#…
kartlee Aug 2, 2020
aef62a9
Remove pre-generated certificates from tests (#331)
dmitris Sep 9, 2020
a4fdb5d
add all make target, reword instructions (#335)
dmitris Sep 9, 2020
88c8444
remove 1.12.x from build config for consistency with master (#337)
dmitris Sep 10, 2020
2a8b5ab
[v2] Fix the special case for jaeger format traceid extraction (#340)
nvx Sep 17, 2020
9d12ea6
Fix ctxtags TagBasedRequestFieldExtractor extracting from fields in a…
nvx Sep 18, 2020
73cf2ae
Request Logging (#311)
yashrsharma44 Oct 2, 2020
7d39267
Bug fix for data race (#354)
yashrsharma44 Nov 19, 2020
38f54d9
make ratelimit interface context aware (#367)
xinxiao Nov 28, 2020
9f6bf00
Added an error param for decider method (#372)
yashrsharma44 Dec 7, 2020
08b17eb
[v2] Add skip interceptor (#364)
XSAM Dec 30, 2020
4a659d8
Remove custom chain middleware (#385)
drewwells Jan 20, 2021
ad3d951
Update travis ci badge to Github actions badge. (#384)
drewwells Jan 20, 2021
c1f1e53
Upgraded proto related deps: grpc and protobuf; removed gogo from cor…
bwplotka Jan 22, 2021
6672a20
improve v2 rate-limiter (#380)
MalloZup Jan 22, 2021
468f615
Moved to buf; Added buf lint; Fixed ping service to match standards; …
bwplotka Jan 22, 2021
3ff779b
Added a timer interface (#387)
yashrsharma44 Jan 28, 2021
20b2825
[Rate-limit provider]: Add token bucket implementation of rate-limite…
MalloZup Jan 29, 2021
215af81
Add OpenMetrics(Prometheus) in the provider module (#379)
yashrsharma44 Jan 29, 2021
524ce8f
v2: Client unary interceptor timeout on v2 branch (#330)
instabledesign Mar 26, 2021
0df73fc
add onRetryCallback callback function (#405)
shamil Apr 3, 2021
0c9d258
port to v2 (#418)
danielhochman Apr 23, 2021
f60016a
Refactor metrics interceptor and fix tests (#413)
ash2k Apr 23, 2021
b81999a
Support customization of timestamp format (v2 branch) (#399)
stanhu Apr 23, 2021
f6fb287
Fixed misleading comments in the interceptor file (#424)
iamrajiv May 27, 2021
cc20532
Switch from github.com/go-kit/kit to github.com/go-kit/log interfaces…
liggitt Jun 19, 2021
0c113ab
v2: Add support for the phuslog logging provider (#425)
ogimenezb Jun 19, 2021
27ca785
v2:providers/zap: fix caller annotation (#432)
jkawamoto Jul 2, 2021
028d350
added dependabot (#376)
iamrajiv Jul 6, 2021
5cdca41
Added a Copyright check in the Makefile (#420)
yashrsharma44 Jul 9, 2021
709d415
Cleanup v2 with some updates (#419)
yashrsharma44 Jul 10, 2021
49d9c0d
openmetrics: forward server context (#434)
Jul 10, 2021
dc87da6
recovery: change the default behavior (#439)
Jul 13, 2021
5b8ad84
Add all-validator support (#443)
leventeliu Jul 23, 2021
7d56e76
Remove backoffutils and added the files to retry package (#390)
yashrsharma44 Aug 3, 2021
274df59
v2:interceptors/logging: add payload decision to separate request res…
michaljemala Aug 7, 2021
f8899ff
Removed tags; Simplified interceptor code; Added logging fields edita…
bwplotka Aug 17, 2021
dd1540e
InterceptorTestSuite client connection optimize (#455)
HUSTtoKTH Aug 31, 2021
32bd5da
Remove opentracing from go.mod (#477)
jpkrohling Dec 2, 2021
ed43ab3
Replace two old Go versions with two new ones (#478)
jpkrohling Dec 3, 2021
a5b9e0b
Move util/metautils to root-level package metadata, fixes #392 (#474)
rahulkhairwar Dec 7, 2021
e4a6915
remove data race from zerolog provider (#487)
ecordell Mar 8, 2022
72478fa
Update provider/kit (#490)
metalmatze Apr 7, 2022
83835dc
Refactor tracing interceptor (#450)
XSAM Apr 25, 2022
58a4066
Add opentracing provider (#492)
XSAM May 5, 2022
5d0f5fe
update phuslog to fix typo (#499)
ogimenezb Jul 14, 2022
f3ab992
Added logr as logging Library provider (#510)
mcdoker18 Aug 30, 2022
001ba37
✨ new feat: selector middleware (#511)
aimuz Sep 7, 2022
cb54482
Add 1.18.x and 1.19.x unit tests (#513)
aimuz Sep 13, 2022
782d4b3
new doc: the format after gofmt (#512)
aimuz Sep 13, 2022
7ac0846
fix provider examples (#529)
forsaken628 Jan 12, 2023
e835172
docs: add `logging.InjectFields` usage description
aimuz Mar 8, 2023
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
Prev Previous commit
Next Next commit
v2: Add support for the phuslog logging provider (#425)
* v2: Add support for the phuslog logging provider

* Update providers/phuslog/logger.go

fallback to error when no level is detected.
Add unknown level With to log and log error message
  • Loading branch information
ogimenezb authored Jun 19, 2021
commit 0c113ab3abcb395970b27ad9bb880109542af0dc
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ myServer := grpc.NewServer(
* [`logrus`](providers/logrus) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers.
* [`kit`](providers/kit) - integration of [go-kit/log](https://github.com/go-kit/log) logging library into gRPC handlers.
* [`zerolog`](providers/zerolog) - integration of [zerolog](https://github.com/rs/zerolog) logging Library into gRPC handlers.
* [`phuslog`](providers/phuslog) - integration of [phuslog](https://github.com/phuslu/log) logging Library into gRPC handlers.

#### Monitoring
* [`grpc_prometheus`⚡](https://github.com/grpc-ecosystem/go-grpc-prometheus) - Prometheus client-side and server-side monitoring middleware
Expand Down
1 change: 1 addition & 0 deletions interceptors/logging/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Implementations:
* providers/zap
* providers/kit
* providers/zerolog
* providers/phuslog

See relevant packages below.
*/
Expand Down
5 changes: 5 additions & 0 deletions providers/phuslog/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
Package phuslog provides a small adapter required to use phuslog in logging gRPC middlewares.
Please see examples for examples of use.
*/
package phuslog
135 changes: 135 additions & 0 deletions providers/phuslog/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package phuslog_test

import (
"context"
"testing"

grpcphuslog "github.com/grpc-ecosystem/go-grpc-middleware/providers/phuslog/v2"
"github.com/phuslu/log"
"google.golang.org/grpc"

middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
)

var (
customFunc logging.CodeToLevel
customDurationToFields logging.DurationToFields
)

func Example_initializationWithCustomLevels() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.DefaultLogger.GrcpGateway()
// Shared options for the logger, with a custom gRPC code to log level function.
opts := []logging.Option{
logging.WithLevels(customFunc),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
middleware.WithUnaryServerChain(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
middleware.WithStreamServerChain(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
)
}

func Example_initializationWithDurationFieldOverride() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.DefaultLogger.GrcpGateway()
// Shared options for the logger, with a custom duration to log field function.
opts := []logging.Option{
logging.WithDurationField(customDurationToFields),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
middleware.WithUnaryServerChain(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
middleware.WithStreamServerChain(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
)
}

func Example_initializationWithCodeGenRequestFieldExtractor() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.DefaultLogger.GrcpGateway()
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
middleware.WithUnaryServerChain(
tags.UnaryServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
),
middleware.WithStreamServerChain(
tags.StreamServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
),
)
}

func ExampleWithDecider() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.DefaultLogger.GrcpGateway()
// Shared options for the logger, with a custom decider that log everything except successful
// calls from "/blah.foo.healthcheck/Check" method.
opts := []logging.Option{
logging.WithDecider(func(methodFullName string) logging.Decision {
// will not log gRPC calls if it was a call to healthcheck and no error was raised
if methodFullName == "/blah.foo.healthcheck/Check" {
return logging.NoLogCall
}

// by default you will log all calls
return logging.LogStartAndFinishCall
}),
}
// Create a server, make sure we put the tags context before everything else.
_ = []grpc.ServerOption{
middleware.WithUnaryServerChain(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
middleware.WithStreamServerChain(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
),
}
}

func ExampleServerPayloadLoggingDecider() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.DefaultLogger.GrcpGateway()
// Expect payload from "/blah.foo.healthcheck/Check" call to be logged.
payloadDecider := func(ctx context.Context, fullMethodName string, servingObject interface{}) bool {
return fullMethodName == "/blah.foo.healthcheck/Check"
}

// Create a server, make sure we put the tags context before everything else.
_ = []grpc.ServerOption{
middleware.WithUnaryServerChain(
tags.UnaryServerInterceptor(),
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
logging.PayloadUnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), payloadDecider),
),
middleware.WithStreamServerChain(
tags.StreamServerInterceptor(),
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
logging.PayloadStreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), payloadDecider),
),
}
}

func TestExamplesBuildable(t *testing.T) {
Example_initializationWithCustomLevels()
Example_initializationWithDurationFieldOverride()
Example_initializationWithCodeGenRequestFieldExtractor()
ExampleWithDecider()
ExampleServerPayloadLoggingDecider()
}
9 changes: 9 additions & 0 deletions providers/phuslog/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/grpc-ecosystem/go-grpc-middleware/providers/phuslog/v2

go 1.14

require (
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201002093600-73cf2ae9d891
github.com/phuslu/log v1.0.72
google.golang.org/grpc v1.30.0
)
79 changes: 79 additions & 0 deletions providers/phuslog/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201002093600-73cf2ae9d891 h1:2F7/en805byWQR92etfFjOqtRtWsUu09R7wm6LtlHEw=
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201002093600-73cf2ae9d891/go.mod h1:GhphxcdlaRyAuBSvo6rV71BvQcvB/vuX8ugCyybuS2k=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/phuslu/log v1.0.72 h1:bjAbUBXqipXi0TCnpkqArnFSU6qd0U+Js5aATJmRj3g=
github.com/phuslu/log v1.0.72/go.mod h1:kzJN3LRifrepxThMjufQwS7S35yFAB+jAV1qgA7eBW4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
47 changes: 47 additions & 0 deletions providers/phuslog/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package phuslog

import (
"fmt"

"github.com/phuslu/log"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
)

// Compatibility check.
var _ logging.Logger = &Logger{}

// Logger is a phuslog logging adapter compatible with logging middlewares.
type Logger struct {
log.GrcpGatewayLogger
}

// InterceptorLogger is a phuslog.Logger to Logger adapter.
func InterceptorLogger(logger log.GrcpGatewayLogger) *Logger {
return &Logger{logger}
}

// Log implements the logging.Logger interface.
func (l *Logger) Log(lvl logging.Level, msg string) {
switch lvl {
case logging.DEBUG:
l.Debug(msg)
case logging.INFO:
l.Info(msg)
case logging.WARNING:
l.Warning(msg)
case logging.ERROR:
l.Error(msg)
default:
l.With("error-lvl", fmt.Sprintf("phuslog: unknown level %s", lvl)).Log(logging.ERROR, msg)
}
}

// With implements the logging.Logger interface.
func (l *Logger) With(fields ...string) logging.Logger {
vals := make([]interface{}, len(fields))
for i := 0; i < len(fields); i++ {
vals[i] = fields[i]
}
return InterceptorLogger(l.WithValues(vals...))
}