log.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package log
  2. import (
  3. "github.com/go-kit/log"
  4. )
  5. // Logger is the fundamental interface for all log operations. Log creates a
  6. // log event from keyvals, a variadic sequence of alternating keys and values.
  7. // Implementations must be safe for concurrent use by multiple goroutines. In
  8. // particular, any implementation of Logger that appends to keyvals or
  9. // modifies or retains any of its elements must make a copy first.
  10. type Logger = log.Logger
  11. // ErrMissingValue is appended to keyvals slices with odd length to substitute
  12. // the missing value.
  13. var ErrMissingValue = log.ErrMissingValue
  14. // With returns a new contextual logger with keyvals prepended to those passed
  15. // to calls to Log. If logger is also a contextual logger created by With,
  16. // WithPrefix, or WithSuffix, keyvals is appended to the existing context.
  17. //
  18. // The returned Logger replaces all value elements (odd indexes) containing a
  19. // Valuer with their generated value for each call to its Log method.
  20. func With(logger Logger, keyvals ...interface{}) Logger {
  21. return log.With(logger, keyvals...)
  22. }
  23. // WithPrefix returns a new contextual logger with keyvals prepended to those
  24. // passed to calls to Log. If logger is also a contextual logger created by
  25. // With, WithPrefix, or WithSuffix, keyvals is prepended to the existing context.
  26. //
  27. // The returned Logger replaces all value elements (odd indexes) containing a
  28. // Valuer with their generated value for each call to its Log method.
  29. func WithPrefix(logger Logger, keyvals ...interface{}) Logger {
  30. return log.WithPrefix(logger, keyvals...)
  31. }
  32. // WithSuffix returns a new contextual logger with keyvals appended to those
  33. // passed to calls to Log. If logger is also a contextual logger created by
  34. // With, WithPrefix, or WithSuffix, keyvals is appended to the existing context.
  35. //
  36. // The returned Logger replaces all value elements (odd indexes) containing a
  37. // Valuer with their generated value for each call to its Log method.
  38. func WithSuffix(logger Logger, keyvals ...interface{}) Logger {
  39. return log.WithSuffix(logger, keyvals...)
  40. }
  41. // LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If
  42. // f is a function with the appropriate signature, LoggerFunc(f) is a Logger
  43. // object that calls f.
  44. type LoggerFunc = log.LoggerFunc