logger.go 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package logger
  2. var (
  3. // DefaultLogger logger
  4. DefaultLogger Logger
  5. )
  6. // Logger is a generic logging interface
  7. type Logger interface {
  8. // Init initialises options
  9. Init(options ...Option) error
  10. // Options The Logger options
  11. Options() Options
  12. // Fields set fields to always be logged
  13. Fields(fields map[string]interface{}) Logger
  14. // Log writes a log entry
  15. Log(level Level, v ...interface{})
  16. // Logf writes a formatted log entry
  17. Logf(level Level, format string, v ...interface{})
  18. // String returns the name of logger
  19. String() string
  20. }
  21. func Init(opts ...Option) error {
  22. return DefaultLogger.Init(opts...)
  23. }
  24. func Fields(fields map[string]interface{}) Logger {
  25. return DefaultLogger.Fields(fields)
  26. }
  27. func Log(level Level, v ...interface{}) {
  28. DefaultLogger.Log(level, v...)
  29. }
  30. func Logf(level Level, format string, v ...interface{}) {
  31. DefaultLogger.Logf(level, format, v...)
  32. }
  33. func String() string {
  34. return DefaultLogger.String()
  35. }