console.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 Daniel Theophanes.
  2. // Use of this source code is governed by a zlib-style
  3. // license that can be found in the LICENSE file.
  4. package service
  5. import (
  6. "log"
  7. "os"
  8. )
  9. // ConsoleLogger logs to the std err.
  10. var ConsoleLogger = consoleLogger{}
  11. type consoleLogger struct {
  12. info, warn, err *log.Logger
  13. }
  14. func init() {
  15. ConsoleLogger.info = log.New(os.Stderr, "I: ", log.Ltime)
  16. ConsoleLogger.warn = log.New(os.Stderr, "W: ", log.Ltime)
  17. ConsoleLogger.err = log.New(os.Stderr, "E: ", log.Ltime)
  18. }
  19. func (c consoleLogger) Error(v ...interface{}) error {
  20. c.err.Print(v...)
  21. return nil
  22. }
  23. func (c consoleLogger) Warning(v ...interface{}) error {
  24. c.warn.Print(v...)
  25. return nil
  26. }
  27. func (c consoleLogger) Info(v ...interface{}) error {
  28. c.info.Print(v...)
  29. return nil
  30. }
  31. func (c consoleLogger) Errorf(format string, a ...interface{}) error {
  32. c.err.Printf(format, a...)
  33. return nil
  34. }
  35. func (c consoleLogger) Warningf(format string, a ...interface{}) error {
  36. c.warn.Printf(format, a...)
  37. return nil
  38. }
  39. func (c consoleLogger) Infof(format string, a ...interface{}) error {
  40. c.info.Printf(format, a...)
  41. return nil
  42. }