Documentation ¶
Overview ¶
Package log is internal log wrapper functionality
Index ¶
- Constants
- func AddToContext(ctx context.Context, l *Logger) context.Context
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func IsSensitiveHeader(name string) bool
- func IsSensitiveParam(name string) bool
- func MaskURL(originalURL string) string
- func NewLoggingContext(ctx context.Context, fields ...interface{}) context.Context
- func OnCloseError(logger *Logger, f io.Closer)
- func OnCloseErrorf(logger *Logger, f io.Closer, format string, v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func Set(l *Logger)
- type BatchConfig
- type ErrFunc
- type Level
- type Logger
- func FromCtx(ctx context.Context) *Logger
- func NewDevLogger(fileLogger *lumberjack.Logger, batchCfg *BatchConfig, stfields ...interface{}) *Logger
- func NewFromConfig(cfg kitconfig.KVStore, path string) (l *Logger, err error)
- func NewLogger(level Level, name string, fileLogger *lumberjack.Logger, batchCfg *BatchConfig, ...) *Logger
- func (l *Logger) AddField(key, value interface{})
- func (l *Logger) Debug(msg string, meta ...interface{})
- func (l *Logger) Error(err error, msg string, meta ...interface{})
- func (l *Logger) Info(msg string, meta ...interface{})
- func (l *Logger) ResetFields()
- func (l *Logger) Set() *Logger
- func (l *Logger) SetFields(dynafields ...interface{})
- func (l *Logger) UpdateLogLevel(level Level)
- func (l *Logger) Warn(msg string, meta ...interface{})
- func (l *Logger) WarnError(err error, msg string, meta ...interface{})
Constants ¶
const RedactionString = "[FILTERED]"
RedactionString represents the filtered value used in place of sensitive data in the log package.
Variables ¶
This section is empty.
Functions ¶
func AddToContext ¶
AddToContext returns new context.Context with additional logger.
func Fatal ¶
func Fatal(v ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func IsSensitiveHeader ¶
IsSensitiveHeader will return true if the given parameter name should be masked for sensitivity.
func IsSensitiveParam ¶
IsSensitiveParam will return true if the given parameter name should be masked for sensitivity.
func MaskURL ¶
MaskURL will mask the sensitive components in an URL with `[FILTERED]`. This list should maintain parity with the list Based on https://stackoverflow.com/a/52965552/474597.
func NewLoggingContext ¶
NewLoggingContext returns a copy of context that also includes a configured logger.
func OnCloseError ¶
OnCloseError execute function f with possible error return. It logs an error if error from f is found it aims to be used for deferred method such : resp.Body.Close(), tx.Rollback() Pass nil as logger to use default package logger So it should be used like: `defer log.OnOnErrorFunc(logger, resp.Body.Close).
func OnCloseErrorf ¶
OnCloseErrorf execute function f with possible error return. It logs an error if error from f is found it aims to be used for deferred method such : resp.Body.Close(), tx.Rollback() Pass nil as logger to use default package logger So it should be used like: `defer log.OnOnErrorFunc(logger, resp.Body.Close, "closing response body for path %s", path).
func Print ¶
func Print(v ...interface{})
Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.
Types ¶
type BatchConfig ¶
BatchConfig is configuration for async log batch writer.
type ErrFunc ¶
type ErrFunc func() error
ErrFunc is any function which takes no argument and possibly returns error e.g. tx.Rollback(), resp.Body.Close().
type Level ¶
type Level int
Level is log output level.
func GetLevelFromString ¶
GetLevelFromString return error level based on config string.
type Logger ¶
type Logger struct { // Level of min logging Level Level // Version Version string // Revision Revision string // DebugLog logger StdLog zerolog.Logger // ErrorLog logger ErrLog zerolog.Logger // contains filtered or unexported fields }
Logger is structured leveled logger.
func FromCtx ¶
FromCtx returns current logger in context. If there is no logger in context it returns a new one with current config values. logger initial attribute fields is copied from existing defaultLogger fields.
func NewDevLogger ¶
func NewDevLogger(fileLogger *lumberjack.Logger, batchCfg *BatchConfig, stfields ...interface{}) *Logger
NewDevLogger logger. Pretty logging for development mode. Not recommended for production use. If static fields are provided those values will define the default static fields for each new built instance if they were not yet configured.
func NewFromConfig ¶
NewFromConfig returns logger based on config file
given config yaml file contents: log: level: info json-enabled: false file: enabled: true path: ./logs/promo-engine.log maxsize-mb: 10 maxage-days: 7 maxbackup-files: 2 batch: enabled: false max-lines: 1000 interval: 15ms then we can call using : v := viper.New() ... set v file configs, etc logger := log.NewFromConfig(v, "log") ..continue using logger.
func NewLogger ¶
func NewLogger(level Level, name string, fileLogger *lumberjack.Logger, batchCfg *BatchConfig, stfields ...interface{}) *Logger
NewLogger logger. If static fields are provided those values will define the default static fields for each new built instance if they were not yet configured.
func (*Logger) AddField ¶
func (l *Logger) AddField(key, value interface{})
AddField add dynamic field key-value The receiver instance will always append these key-value pairs to the output.
func (*Logger) ResetFields ¶
func (l *Logger) ResetFields()
ResetFields clear all the logger's assigned dymanic fields Remove dynamic fields.
func (*Logger) Set ¶
Set default package logger. Can be used chained with NewLogger to create a new one, set it up as package default logger and get it for use in one step. i.e: logger := log.NewLogger(log.Debug, "name", "version", "revision").Set().
func (*Logger) SetFields ¶
func (l *Logger) SetFields(dynafields ...interface{})
SetFields set logger dynamic fields. The receiver instance will always append these key-value pairs to the output.
func (*Logger) UpdateLogLevel ¶
UpdateLogLevel updates log level.