Documentation ¶
Index ¶
- Constants
- type LogHookFunc
- type Logger
- func (v *Logger) CreateScoped(scope interface{}) *Logger
- func (v *Logger) Debug(msgs ...interface{})
- func (v *Logger) Error(err error)
- func (v *Logger) ErrorString(msgs ...interface{})
- func (v *Logger) Info(msgs ...interface{})
- func (v *Logger) Trace(fnName string) func()
- func (v *Logger) Warn(msgs ...interface{})
- type Options
- type OptionsModifier
- func AppMeta(meta interface{}) OptionsModifier
- func EnvPrefix(envPrefix string) OptionsModifier
- func Level(level string) OptionsModifier
- func LogPrefix(logPrefix string) OptionsModifier
- func PreLogHook(hook LogHookFunc) OptionsModifier
- func ToFile(filepath string) OptionsModifier
- func WithWriter(writer io.Writer) OptionsModifier
- type Producer
- type SafeStringer
Constants ¶
const ( LogLevelTrace = "trace" // 5 LogLevelDebug = "debug" // 4 LogLevelInfo = "info" // 3 LogLevelWarn = "warn" // 2 LogLevelError = "error" // 1 LogLevelNull = "null" // 0 )
LogLevelTrace and others represent log levels
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogHookFunc ¶ added in v0.4.1
type LogHookFunc func([]byte)
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the main logger object, responsible for taking input from the producer and managing scoped loggers
func Default ¶ added in v0.1.2
func Default(opts ...OptionsModifier) *Logger
Default returns a Logger using the default producer
func New ¶ added in v0.1.2
func New(producer Producer, opts ...OptionsModifier) *Logger
New returns a Logger with the provided producer and options
func (*Logger) CreateScoped ¶ added in v0.1.2
CreateScoped creates a duplicate logger which has a particular scope
func (*Logger) Debug ¶
func (v *Logger) Debug(msgs ...interface{})
Debug logs a string as debug output
func (*Logger) ErrorString ¶
func (v *Logger) ErrorString(msgs ...interface{})
ErrorString logs a string as an error
func (*Logger) Info ¶
func (v *Logger) Info(msgs ...interface{})
Info logs a string as an info message
type Options ¶ added in v0.1.2
type Options struct { Level int LevelString string `env:"LOG_LEVEL"` Filepath string `env:"LOG_FILE"` LogPrefix string `env:"LOG_PREFIX"` OutputWriter io.Writer EnvPrefix string AppMeta interface{} PreLogHook LogHookFunc }
Options represents the options for a VLogger
type OptionsModifier ¶ added in v0.1.2
type OptionsModifier func(*Options)
OptionsModifier is a options modifier function
func AppMeta ¶ added in v0.2.0
func AppMeta(meta interface{}) OptionsModifier
AppMeta sets the AppMeta object to be included with structured logs
func EnvPrefix ¶ added in v0.2.5
func EnvPrefix(envPrefix string) OptionsModifier
EnvPrefix sets a prefix for evaluating logger settings from env
func Level ¶ added in v0.1.2
func Level(level string) OptionsModifier
Level sets the logging level to one of error, warn, info, debug, or trace
func LogPrefix ¶ added in v0.2.5
func LogPrefix(logPrefix string) OptionsModifier
LogPrefix sets a prefix on all of the log messages
func PreLogHook ¶ added in v0.4.1
func PreLogHook(hook LogHookFunc) OptionsModifier
PreLogHook sets a function to be run before each logged value
func ToFile ¶ added in v0.1.2
func ToFile(filepath string) OptionsModifier
ToFile sets the logger to open the file specified and write logs to it
func WithWriter ¶ added in v0.5.3
func WithWriter(writer io.Writer) OptionsModifier
WithWriter configures the logger to write its logs to the supplied writer
type Producer ¶ added in v0.1.2
type Producer interface { ErrorString(...interface{}) string // Logs an error string Error(error) string // Logs an error obj Warn(...interface{}) string // Logs a warning Info(...interface{}) string // Logs information Debug(...interface{}) string // Logs debug information Trace(string) (string, func() string) // Logs a function name and returns a function to be deferred, indicating the end of the function }
Producer represents an object that is considered a producer of messages
type SafeStringer ¶ added in v0.2.3
type SafeStringer interface {
SafeString() string
}
SafeStringer allows a struct to produse a "safe" string representation for logging the intention is avoiding accidentally including sensitive information in struct fields.