1/* 2Copyright 2016 Euan Kemp 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package kmsgparser 18 19import stdlog "log" 20 21// Logger is a glog compatible logging interface 22// The StandardLogger struct can be used to wrap a log.Logger from the golang 23// "log" package to create a standard a logger fulfilling this interface as 24// well. 25type Logger interface { 26 Warningf(string, ...interface{}) 27 Infof(string, ...interface{}) 28 Errorf(string, ...interface{}) 29} 30 31// StandardLogger adapts the "log" package's Logger interface to be a Logger 32type StandardLogger struct { 33 *stdlog.Logger 34} 35 36func (s *StandardLogger) Warningf(fmt string, args ...interface{}) { 37 if s.Logger == nil { 38 return 39 } 40 s.Logger.Printf("[WARNING] "+fmt, args) 41} 42 43func (s *StandardLogger) Infof(fmt string, args ...interface{}) { 44 if s.Logger == nil { 45 return 46 } 47 s.Logger.Printf("[INFO] "+fmt, args) 48} 49 50func (s *StandardLogger) Errorf(fmt string, args ...interface{}) { 51 if s.Logger == nil { 52 return 53 } 54 s.Logger.Printf("[INFO] "+fmt, args) 55} 56