logutil

package
v1.1.0-beta.0...-604b0d6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CondUint32

func CondUint32(key string, val uint32, condition bool) zap.Field

CondUint32 constructs a field with the given key and value conditionally. If the condition is true, it constructs a field with uint32 type; otherwise, skip the field.

func IsLevelLegal

func IsLevelLegal(level string) bool

IsLevelLegal checks whether the level is legal.

func LogPanic

func LogPanic()

LogPanic logs the panic reason and stack, then exit the process. Commonly used with a `defer`.

func RedactBytes

func RedactBytes(arg []byte) []byte

RedactBytes receives []byte argument and return omitted information if redact log enabled

func RedactString

func RedactString(arg string) string

RedactString receives string argument and return omitted information if redact log enabled

func RedactStringer

func RedactStringer(arg fmt.Stringer) fmt.Stringer

RedactStringer receives stringer argument and return omitted information if redact log enabled

func SetupLogger

func SetupLogger(
	logConfig log.Config,
	logger **zap.Logger,
	logProps **log.ZapProperties,
	redactInfoLogType RedactInfoLogType,
) error

SetupLogger setup the logger.

func StringToZapLogLevel

func StringToZapLogLevel(level string) zapcore.Level

StringToZapLogLevel translates log level string to log level.

func ZapRedactByteString

func ZapRedactByteString(key string, arg []byte) zap.Field

ZapRedactByteString receives []byte argument and return omitted information zap.Field if redact log enabled

func ZapRedactString

func ZapRedactString(key, arg string) zap.Field

ZapRedactString receives string argument and return omitted information in zap.Field if redact log enabled

func ZapRedactStringer

func ZapRedactStringer(key string, arg fmt.Stringer) zap.Field

ZapRedactStringer receives stringer argument and return omitted information in zap.Field if redact log enabled

Types

type FileLogConfig

type FileLogConfig struct {
	// Log filename, leave empty to disable file log.
	Filename string `toml:"filename" json:"filename"`
	// Max size for a single file, in MB.
	MaxSize int `toml:"max-size" json:"max-size"`
	// Max log keep days, default is never deleting.
	MaxDays int `toml:"max-days" json:"max-days"`
	// Maximum number of old log files to retain.
	MaxBackups int `toml:"max-backups" json:"max-backups"`
}

FileLogConfig serializes file log related config in toml/json.

type LogConfig

type LogConfig struct {
	// Log level.
	Level string `toml:"level" json:"level"`
	// Log format. one of json, text, or console.
	Format string `toml:"format" json:"format"`
	// Disable automatic timestamps in output.
	DisableTimestamp bool `toml:"disable-timestamp" json:"disable-timestamp"`
	// File log config.
	File FileLogConfig `toml:"file" json:"file"`
}

LogConfig serializes log related config in toml/json.

type RedactInfoLogType

type RedactInfoLogType int

RedactInfoLogType is the behavior of redacting sensitive information in logs.

const (
	// RedactInfoLogOFF means log redaction is disabled.
	RedactInfoLogOFF RedactInfoLogType = iota
	// RedactInfoLogON means log redaction is enabled, and will replace the sensitive information with "?".
	RedactInfoLogON
	// RedactInfoLogMarker means log redaction is enabled, and will use single guillemets ‹› to enclose the sensitive information.
	RedactInfoLogMarker
)

func (RedactInfoLogType) MarshalJSON

func (t RedactInfoLogType) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface to ensure the compatibility.

func (*RedactInfoLogType) UnmarshalJSON

func (t *RedactInfoLogType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Marshaler` interface to ensure the compatibility.

func (*RedactInfoLogType) UnmarshalTOML

func (t *RedactInfoLogType) UnmarshalTOML(data any) error

UnmarshalTOML implements the `toml.Unmarshaler` interface to ensure the compatibility.

Jump to

Keyboard shortcuts

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