1// Copyright 2020 Envoyproxy 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
15// Package log provides a logging interface for use in this library.
16package log
17
18// Logger interface for reporting informational and warning messages.
19type Logger interface {
20	// Debugf logs a formatted debugging message.
21	Debugf(format string, args ...interface{})
22
23	// Infof logs a formatted informational message.
24	Infof(format string, args ...interface{})
25
26	// Warnf logs a formatted warning message.
27	Warnf(format string, args ...interface{})
28
29	// Errorf logs a formatted error message.
30	Errorf(format string, args ...interface{})
31}
32
33// LoggerFuncs implements the Logger interface, allowing the
34// caller to specify only the logging functions that are desired.
35type LoggerFuncs struct {
36	DebugFunc func(string, ...interface{})
37	InfoFunc  func(string, ...interface{})
38	WarnFunc  func(string, ...interface{})
39	ErrorFunc func(string, ...interface{})
40}
41
42// Debugf logs a formatted debugging message.
43func (f LoggerFuncs) Debugf(format string, args ...interface{}) {
44	if f.DebugFunc != nil {
45		f.DebugFunc(format, args...)
46	}
47}
48
49// Infof logs a formatted informational message.
50func (f LoggerFuncs) Infof(format string, args ...interface{}) {
51	if f.InfoFunc != nil {
52		f.InfoFunc(format, args...)
53	}
54}
55
56// Warnf logs a formatted warning message.
57func (f LoggerFuncs) Warnf(format string, args ...interface{}) {
58	if f.WarnFunc != nil {
59		f.WarnFunc(format, args...)
60	}
61}
62
63// Errorf logs a formatted error message.
64func (f LoggerFuncs) Errorf(format string, args ...interface{}) {
65	if f.ErrorFunc != nil {
66		f.ErrorFunc(format, args...)
67	}
68}
69