interface.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package lgr
  2. import stdlog "log"
  3. var def = New() // default logger doesn't allow DEBUG and doesn't add caller info
  4. // L defines minimal interface used to log things
  5. type L interface {
  6. Logf(format string, args ...interface{})
  7. }
  8. // Func type is an adapter to allow the use of ordinary functions as Logger.
  9. type Func func(format string, args ...interface{})
  10. // Logf calls f(id)
  11. func (f Func) Logf(format string, args ...interface{}) { f(format, args...) }
  12. // NoOp logger
  13. var NoOp = Func(func(format string, args ...interface{}) {})
  14. // Std logger sends to std default logger directly
  15. var Std = Func(func(format string, args ...interface{}) { stdlog.Printf(format, args...) })
  16. // Printf simplifies replacement of std logger
  17. func Printf(format string, args ...interface{}) {
  18. def.Logf(format, args...)
  19. }
  20. // Print simplifies replacement of std logger
  21. func Print(line string) {
  22. def.Logf(line)
  23. }
  24. // Setup default logger with options
  25. func Setup(opts ...Option) {
  26. def = New(opts...)
  27. def.skipCallers = 2
  28. }
  29. // Default returns pre-constructed def logger (debug on, callers disabled)
  30. func Default() L { return def }