1// Copyright © 2017 VMware, Inc. All Rights Reserved. 2// SPDX-License-Identifier: BSD-2-Clause 3// 4// Copyright 2016 VMware, Inc. All Rights Reserved. 5// 6// Licensed under the Apache License, Version 2.0 (the "License"); 7// you may not use this file except in compliance with the License. 8// You may obtain a copy of the License at 9// 10// http://www.apache.org/licenses/LICENSE-2.0 11// 12// Unless required by applicable law or agreed to in writing, software 13// distributed under the License is distributed on an "AS IS" BASIS, 14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15// See the License for the specific language governing permissions and 16// limitations under the License. 17 18package util 19 20import "log" 21 22var DefaultLogger Logger 23 24type Logger interface { 25 SetDebug(bool) 26 Errorf(format string, args ...interface{}) 27 Debugf(format string, args ...interface{}) 28 Infof(format string, args ...interface{}) 29} 30 31func init() { 32 DefaultLogger = &logger{} 33} 34 35type logger struct { 36 DebugLevel bool 37} 38 39func (l *logger) SetDebug(enable bool) { 40 l.DebugLevel = enable 41} 42 43func (l *logger) Errorf(format string, args ...interface{}) { 44 log.Printf(format, args...) 45} 46 47func (l *logger) Debugf(format string, args ...interface{}) { 48 if !l.DebugLevel { 49 return 50 } 51 52 log.Printf(format, args...) 53} 54 55func (l *logger) Infof(format string, args ...interface{}) { 56 log.Printf(format, args...) 57} 58 59func Errorf(format string, args ...interface{}) { 60 DefaultLogger.Errorf(format, args...) 61} 62 63func Debugf(format string, args ...interface{}) { 64 DefaultLogger.Debugf(format, args...) 65} 66 67func Infof(format string, args ...interface{}) { 68 DefaultLogger.Infof(format, args...) 69} 70