Skip to content

Commit 0c113ab

Browse files
authored
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
1 parent cc20532 commit 0c113ab

File tree

7 files changed

+277
-0
lines changed

7 files changed

+277
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ myServer := grpc.NewServer(
6363
* [`logrus`](providers/logrus) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers.
6464
* [`kit`](providers/kit) - integration of [go-kit/log](https://github.com/go-kit/log) logging library into gRPC handlers.
6565
* [`zerolog`](providers/zerolog) - integration of [zerolog](https://github.com/rs/zerolog) logging Library into gRPC handlers.
66+
* [`phuslog`](providers/phuslog) - integration of [phuslog](https://github.com/phuslu/log) logging Library into gRPC handlers.
6667

6768
#### Monitoring
6869
* [`grpc_prometheus`](https://github.com/grpc-ecosystem/go-grpc-prometheus) - Prometheus client-side and server-side monitoring middleware

interceptors/logging/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Implementations:
3030
* providers/zap
3131
* providers/kit
3232
* providers/zerolog
33+
* providers/phuslog
3334
3435
See relevant packages below.
3536
*/

providers/phuslog/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
Package phuslog provides a small adapter required to use phuslog in logging gRPC middlewares.
3+
Please see examples for examples of use.
4+
*/
5+
package phuslog

providers/phuslog/examples_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package phuslog_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
grpcphuslog "github.com/grpc-ecosystem/go-grpc-middleware/providers/phuslog/v2"
8+
"github.com/phuslu/log"
9+
"google.golang.org/grpc"
10+
11+
middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2"
12+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
13+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
14+
)
15+
16+
var (
17+
customFunc logging.CodeToLevel
18+
customDurationToFields logging.DurationToFields
19+
)
20+
21+
func Example_initializationWithCustomLevels() {
22+
// Logger is used, allowing pre-definition of certain fields by the user.
23+
logger := log.DefaultLogger.GrcpGateway()
24+
// Shared options for the logger, with a custom gRPC code to log level function.
25+
opts := []logging.Option{
26+
logging.WithLevels(customFunc),
27+
}
28+
// Create a server, make sure we put the tags context before everything else.
29+
_ = grpc.NewServer(
30+
middleware.WithUnaryServerChain(
31+
tags.UnaryServerInterceptor(),
32+
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
33+
),
34+
middleware.WithStreamServerChain(
35+
tags.StreamServerInterceptor(),
36+
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
37+
),
38+
)
39+
}
40+
41+
func Example_initializationWithDurationFieldOverride() {
42+
// Logger is used, allowing pre-definition of certain fields by the user.
43+
logger := log.DefaultLogger.GrcpGateway()
44+
// Shared options for the logger, with a custom duration to log field function.
45+
opts := []logging.Option{
46+
logging.WithDurationField(customDurationToFields),
47+
}
48+
// Create a server, make sure we put the tags context before everything else.
49+
_ = grpc.NewServer(
50+
middleware.WithUnaryServerChain(
51+
tags.UnaryServerInterceptor(),
52+
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
53+
),
54+
middleware.WithStreamServerChain(
55+
tags.StreamServerInterceptor(),
56+
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
57+
),
58+
)
59+
}
60+
61+
func Example_initializationWithCodeGenRequestFieldExtractor() {
62+
// Logger is used, allowing pre-definition of certain fields by the user.
63+
logger := log.DefaultLogger.GrcpGateway()
64+
// Create a server, make sure we put the tags context before everything else.
65+
_ = grpc.NewServer(
66+
middleware.WithUnaryServerChain(
67+
tags.UnaryServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
68+
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
69+
),
70+
middleware.WithStreamServerChain(
71+
tags.StreamServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)),
72+
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
73+
),
74+
)
75+
}
76+
77+
func ExampleWithDecider() {
78+
// Logger is used, allowing pre-definition of certain fields by the user.
79+
logger := log.DefaultLogger.GrcpGateway()
80+
// Shared options for the logger, with a custom decider that log everything except successful
81+
// calls from "/blah.foo.healthcheck/Check" method.
82+
opts := []logging.Option{
83+
logging.WithDecider(func(methodFullName string) logging.Decision {
84+
// will not log gRPC calls if it was a call to healthcheck and no error was raised
85+
if methodFullName == "/blah.foo.healthcheck/Check" {
86+
return logging.NoLogCall
87+
}
88+
89+
// by default you will log all calls
90+
return logging.LogStartAndFinishCall
91+
}),
92+
}
93+
// Create a server, make sure we put the tags context before everything else.
94+
_ = []grpc.ServerOption{
95+
middleware.WithUnaryServerChain(
96+
tags.UnaryServerInterceptor(),
97+
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
98+
),
99+
middleware.WithStreamServerChain(
100+
tags.StreamServerInterceptor(),
101+
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), opts...),
102+
),
103+
}
104+
}
105+
106+
func ExampleServerPayloadLoggingDecider() {
107+
// Logger is used, allowing pre-definition of certain fields by the user.
108+
logger := log.DefaultLogger.GrcpGateway()
109+
// Expect payload from "/blah.foo.healthcheck/Check" call to be logged.
110+
payloadDecider := func(ctx context.Context, fullMethodName string, servingObject interface{}) bool {
111+
return fullMethodName == "/blah.foo.healthcheck/Check"
112+
}
113+
114+
// Create a server, make sure we put the tags context before everything else.
115+
_ = []grpc.ServerOption{
116+
middleware.WithUnaryServerChain(
117+
tags.UnaryServerInterceptor(),
118+
logging.UnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
119+
logging.PayloadUnaryServerInterceptor(grpcphuslog.InterceptorLogger(logger), payloadDecider),
120+
),
121+
middleware.WithStreamServerChain(
122+
tags.StreamServerInterceptor(),
123+
logging.StreamServerInterceptor(grpcphuslog.InterceptorLogger(logger)),
124+
logging.PayloadStreamServerInterceptor(grpcphuslog.InterceptorLogger(logger), payloadDecider),
125+
),
126+
}
127+
}
128+
129+
func TestExamplesBuildable(t *testing.T) {
130+
Example_initializationWithCustomLevels()
131+
Example_initializationWithDurationFieldOverride()
132+
Example_initializationWithCodeGenRequestFieldExtractor()
133+
ExampleWithDecider()
134+
ExampleServerPayloadLoggingDecider()
135+
}

providers/phuslog/go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/grpc-ecosystem/go-grpc-middleware/providers/phuslog/v2
2+
3+
go 1.14
4+
5+
require (
6+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201002093600-73cf2ae9d891
7+
github.com/phuslu/log v1.0.72
8+
google.golang.org/grpc v1.30.0
9+
)

providers/phuslog/go.sum

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

providers/phuslog/logger.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package phuslog
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/phuslu/log"
7+
8+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
9+
)
10+
11+
// Compatibility check.
12+
var _ logging.Logger = &Logger{}
13+
14+
// Logger is a phuslog logging adapter compatible with logging middlewares.
15+
type Logger struct {
16+
log.GrcpGatewayLogger
17+
}
18+
19+
// InterceptorLogger is a phuslog.Logger to Logger adapter.
20+
func InterceptorLogger(logger log.GrcpGatewayLogger) *Logger {
21+
return &Logger{logger}
22+
}
23+
24+
// Log implements the logging.Logger interface.
25+
func (l *Logger) Log(lvl logging.Level, msg string) {
26+
switch lvl {
27+
case logging.DEBUG:
28+
l.Debug(msg)
29+
case logging.INFO:
30+
l.Info(msg)
31+
case logging.WARNING:
32+
l.Warning(msg)
33+
case logging.ERROR:
34+
l.Error(msg)
35+
default:
36+
l.With("error-lvl", fmt.Sprintf("phuslog: unknown level %s", lvl)).Log(logging.ERROR, msg)
37+
}
38+
}
39+
40+
// With implements the logging.Logger interface.
41+
func (l *Logger) With(fields ...string) logging.Logger {
42+
vals := make([]interface{}, len(fields))
43+
for i := 0; i < len(fields); i++ {
44+
vals[i] = fields[i]
45+
}
46+
return InterceptorLogger(l.WithValues(vals...))
47+
}

0 commit comments

Comments
 (0)