项目作者: hassieswift621

项目描述 :
gRPC Go middleware for Cdr's Slog logger
高级语言: Go
项目地址: git://github.com/hassieswift621/slog-grpc-mw.git
创建时间: 2020-03-21T11:25:06Z
项目社区:https://github.com/hassieswift621/slog-grpc-mw

开源协议:Apache License 2.0

下载


slog-grpc-mw

mw@v1.0.0?tab=doc">Godoc reference
GitHub release (latest by date)

gRPC Go middleware for Cdr’s Slog logger: https://github.com/cdr/slog

Output Screenshot

Install

  1. go get github.com/hassieswift621/slog-grpc-mw

Example Usage

  1. func main() {
  2. // Create GRPC server.
  3. srv := grpc.NewServer(
  4. grpc.UnaryInterceptor(
  5. grpc_middleware.ChainUnaryServer(
  6. grpc_slog.UnaryServerInterceptor(grpcLogger(true)),
  7. ),
  8. ),
  9. )
  10. }
  11. func grpcLogger(verbose bool) slog.Logger {
  12. logger := sloghuman.Make(os.Stdout).Leveled(slog.LevelWarn).Named("grpc")
  13. if verbose {
  14. logger = logger.Leveled(slog.LevelDebug)
  15. }
  16. return logger
  17. }

License

  1. Copyright ©2020 Hassie.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.