log.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2016 Euan Kemp
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package kmsgparser
  14. import stdlog "log"
  15. // Logger is a glog compatible logging interface
  16. // The StandardLogger struct can be used to wrap a log.Logger from the golang
  17. // "log" package to create a standard a logger fulfilling this interface as
  18. // well.
  19. type Logger interface {
  20. Warningf(string, ...interface{})
  21. Infof(string, ...interface{})
  22. Errorf(string, ...interface{})
  23. }
  24. // StandardLogger adapts the "log" package's Logger interface to be a Logger
  25. type StandardLogger struct {
  26. *stdlog.Logger
  27. }
  28. func (s *StandardLogger) Warningf(fmt string, args ...interface{}) {
  29. if s.Logger == nil {
  30. return
  31. }
  32. s.Logger.Printf("[WARNING] "+fmt, args)
  33. }
  34. func (s *StandardLogger) Infof(fmt string, args ...interface{}) {
  35. if s.Logger == nil {
  36. return
  37. }
  38. s.Logger.Printf("[INFO] "+fmt, args)
  39. }
  40. func (s *StandardLogger) Errorf(fmt string, args ...interface{}) {
  41. if s.Logger == nil {
  42. return
  43. }
  44. s.Logger.Printf("[INFO] "+fmt, args)
  45. }