logrusutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logrusutil implements some helpers for using logrus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComponentInit

func ComponentInit()

ComponentInit is a syntax sugar for easier Init

func Init

func Init(formatter *DefaultFieldsFormatter)

Init set Logrus formatter if DefaultFieldsFormatter.wrappedFormatter is nil &logrus.JSONFormatter{} will be used instead

func ThrottledWarnf

func ThrottledWarnf(last *time.Time, period time.Duration, format string, args ...interface{})

ThrottledWarnf prints a warning the first time called and if at most `period` has elapsed since the last time.

Types

type CensoringFormatter

type CensoringFormatter struct {
	// contains filtered or unexported fields
}

CensoringFormatter represents a logrus formatter that can be used to censor sensitive information

func NewCensoringFormatter

func NewCensoringFormatter(f logrus.Formatter, getSecrets func() sets.String) CensoringFormatter

NewCensoringFormatter generates a `CensoringFormatter` with a formatter as delegate and a set of strings to censor

func NewFormatterWithCensor

func NewFormatterWithCensor(f logrus.Formatter, censorer secretutil.Censorer) CensoringFormatter

NewFormatterWithCensor generates a `CensoringFormatter` with a formatter as delegate and censorer to use

func (CensoringFormatter) Format

func (f CensoringFormatter) Format(entry *logrus.Entry) ([]byte, error)

type DefaultFieldsFormatter

type DefaultFieldsFormatter struct {
	WrappedFormatter logrus.Formatter
	DefaultFields    logrus.Fields
	PrintLineNumber  bool
}

DefaultFieldsFormatter wraps another logrus.Formatter, injecting DefaultFields into each Format() call, existing fields are preserved if they have the same key

func (*DefaultFieldsFormatter) Format

func (f *DefaultFieldsFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter's Format. We allocate a new Fields map in order to not modify the caller's Entry, as that is not a thread safe operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL