log.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2016 VMware, Inc. All Rights Reserved.
  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. package message
  15. import "log"
  16. var DefaultLogger Logger
  17. type Logger interface {
  18. Errorf(format string, args ...interface{})
  19. Debugf(format string, args ...interface{})
  20. Infof(format string, args ...interface{})
  21. }
  22. func init() {
  23. DefaultLogger = &logger{}
  24. }
  25. type logger struct {
  26. DebugLevel bool
  27. }
  28. func (l *logger) Errorf(format string, args ...interface{}) {
  29. log.Printf(format, args...)
  30. }
  31. func (l *logger) Debugf(format string, args ...interface{}) {
  32. if !l.DebugLevel {
  33. return
  34. }
  35. log.Printf(format, args...)
  36. }
  37. func (l *logger) Infof(format string, args ...interface{}) {
  38. log.Printf(format, args...)
  39. }
  40. func Errorf(format string, args ...interface{}) {
  41. DefaultLogger.Errorf(format, args...)
  42. }
  43. func Debugf(format string, args ...interface{}) {
  44. DefaultLogger.Debugf(format, args...)
  45. }
  46. func Infof(format string, args ...interface{}) {
  47. DefaultLogger.Infof(format, args...)
  48. }