...

Source file src/github.com/go-kit/kit/log/level/level.go

Documentation: github.com/go-kit/kit/log/level

     1  package level
     2  
     3  import (
     4  	"github.com/go-kit/log"
     5  	"github.com/go-kit/log/level"
     6  )
     7  
     8  // Error returns a logger that includes a Key/ErrorValue pair.
     9  func Error(logger log.Logger) log.Logger {
    10  	return level.Error(logger)
    11  }
    12  
    13  // Warn returns a logger that includes a Key/WarnValue pair.
    14  func Warn(logger log.Logger) log.Logger {
    15  	return level.Warn(logger)
    16  }
    17  
    18  // Info returns a logger that includes a Key/InfoValue pair.
    19  func Info(logger log.Logger) log.Logger {
    20  	return level.Info(logger)
    21  }
    22  
    23  // Debug returns a logger that includes a Key/DebugValue pair.
    24  func Debug(logger log.Logger) log.Logger {
    25  	return level.Debug(logger)
    26  }
    27  
    28  // NewFilter wraps next and implements level filtering. See the commentary on
    29  // the Option functions for a detailed description of how to configure levels.
    30  // If no options are provided, all leveled log events created with Debug,
    31  // Info, Warn or Error helper methods are squelched and non-leveled log
    32  // events are passed to next unmodified.
    33  func NewFilter(next log.Logger, options ...Option) log.Logger {
    34  	return level.NewFilter(next, options...)
    35  }
    36  
    37  // Option sets a parameter for the leveled logger.
    38  type Option = level.Option
    39  
    40  // AllowAll is an alias for AllowDebug.
    41  func AllowAll() Option {
    42  	return level.AllowAll()
    43  }
    44  
    45  // AllowDebug allows error, warn, info and debug level log events to pass.
    46  func AllowDebug() Option {
    47  	return level.AllowDebug()
    48  }
    49  
    50  // AllowInfo allows error, warn and info level log events to pass.
    51  func AllowInfo() Option {
    52  	return level.AllowInfo()
    53  }
    54  
    55  // AllowWarn allows error and warn level log events to pass.
    56  func AllowWarn() Option {
    57  	return level.AllowWarn()
    58  }
    59  
    60  // AllowError allows only error level log events to pass.
    61  func AllowError() Option {
    62  	return level.AllowError()
    63  }
    64  
    65  // AllowNone allows no leveled log events to pass.
    66  func AllowNone() Option {
    67  	return level.AllowNone()
    68  }
    69  
    70  // ErrNotAllowed sets the error to return from Log when it squelches a log
    71  // event disallowed by the configured Allow[Level] option. By default,
    72  // ErrNotAllowed is nil; in this case the log event is squelched with no
    73  // error.
    74  func ErrNotAllowed(err error) Option {
    75  	return level.ErrNotAllowed(err)
    76  }
    77  
    78  // SquelchNoLevel instructs Log to squelch log events with no level, so that
    79  // they don't proceed through to the wrapped logger. If SquelchNoLevel is set
    80  // to true and a log event is squelched in this way, the error value
    81  // configured with ErrNoLevel is returned to the caller.
    82  func SquelchNoLevel(squelch bool) Option {
    83  	return level.SquelchNoLevel(squelch)
    84  }
    85  
    86  // ErrNoLevel sets the error to return from Log when it squelches a log event
    87  // with no level. By default, ErrNoLevel is nil; in this case the log event is
    88  // squelched with no error.
    89  func ErrNoLevel(err error) Option {
    90  	return level.ErrNoLevel(err)
    91  }
    92  
    93  // NewInjector wraps next and returns a logger that adds a Key/level pair to
    94  // the beginning of log events that don't already contain a level. In effect,
    95  // this gives a default level to logs without a level.
    96  func NewInjector(next log.Logger, lvl Value) log.Logger {
    97  	return level.NewInjector(next, lvl)
    98  }
    99  
   100  // Value is the interface that each of the canonical level values implement.
   101  // It contains unexported methods that prevent types from other packages from
   102  // implementing it and guaranteeing that NewFilter can distinguish the levels
   103  // defined in this package from all other values.
   104  type Value = level.Value
   105  
   106  // Key returns the unique key added to log events by the loggers in this
   107  // package.
   108  func Key() interface{} { return level.Key() }
   109  
   110  // ErrorValue returns the unique value added to log events by Error.
   111  func ErrorValue() Value { return level.ErrorValue() }
   112  
   113  // WarnValue returns the unique value added to log events by Warn.
   114  func WarnValue() Value { return level.WarnValue() }
   115  
   116  // InfoValue returns the unique value added to log events by Info.
   117  func InfoValue() Value { return level.InfoValue() }
   118  
   119  // DebugValue returns the unique value added to log events by Debug.
   120  func DebugValue() Value { return level.DebugValue() }
   121  

View as plain text