blob: 729cbdb57e4d67971860e830981a90596626555a [file] [log] [blame]
divyadesai19009132020-03-04 12:58:08 +00001// Copyright 2018 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package logutil
16
17import (
18 "github.com/coreos/pkg/capnslog"
19 "google.golang.org/grpc/grpclog"
20)
21
22// assert that "packageLogger" satisfy "Logger" interface
23var _ Logger = &packageLogger{}
24
25// NewPackageLogger wraps "*capnslog.PackageLogger" that implements "Logger" interface.
26//
27// For example:
28//
29// var defaultLogger Logger
30// defaultLogger = NewPackageLogger("go.etcd.io/etcd", "snapshot")
31//
32func NewPackageLogger(repo, pkg string) Logger {
33 return &packageLogger{p: capnslog.NewPackageLogger(repo, pkg)}
34}
35
36type packageLogger struct {
37 p *capnslog.PackageLogger
38}
39
40func (l *packageLogger) Info(args ...interface{}) { l.p.Info(args...) }
41func (l *packageLogger) Infoln(args ...interface{}) { l.p.Info(args...) }
42func (l *packageLogger) Infof(format string, args ...interface{}) { l.p.Infof(format, args...) }
43func (l *packageLogger) Warning(args ...interface{}) { l.p.Warning(args...) }
44func (l *packageLogger) Warningln(args ...interface{}) { l.p.Warning(args...) }
45func (l *packageLogger) Warningf(format string, args ...interface{}) { l.p.Warningf(format, args...) }
46func (l *packageLogger) Error(args ...interface{}) { l.p.Error(args...) }
47func (l *packageLogger) Errorln(args ...interface{}) { l.p.Error(args...) }
48func (l *packageLogger) Errorf(format string, args ...interface{}) { l.p.Errorf(format, args...) }
49func (l *packageLogger) Fatal(args ...interface{}) { l.p.Fatal(args...) }
50func (l *packageLogger) Fatalln(args ...interface{}) { l.p.Fatal(args...) }
51func (l *packageLogger) Fatalf(format string, args ...interface{}) { l.p.Fatalf(format, args...) }
52func (l *packageLogger) V(lvl int) bool {
53 return l.p.LevelAt(capnslog.LogLevel(lvl))
54}
55func (l *packageLogger) Lvl(lvl int) grpclog.LoggerV2 {
56 if l.p.LevelAt(capnslog.LogLevel(lvl)) {
57 return l
58 }
59 return &discardLogger{}
60}