logx

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package logx - an extension of logrus library. This package loads configurations from cfgx and create global logrus.Logger object. We can use logx like:

logx.Debug()
logx.Info()
...

See Config for more information about configuration options.

Index

Constants

View Source
const (
	KeyLevel                  = "logger.level"
	KeyWithCaller             = "logger.with.caller"
	KeyFormatterType          = "logger.formatter.type"
	KeyTimestampEnable        = "logger.formatter.timestamp.enable"
	KeyTimestampFormat        = "logger.formatter.timestamp.format"
	KeyPadLevelText           = "logger.formatter.pad.level.text"
	KeyStdoutEnable           = "logger.output.stdout.enable"
	KeyFileEnable             = "logger.output.file.enable"
	KeyFileDir                = "logger.output.file.dir"
	KeyFileName               = "logger.output.file.name"
	KeyFileRotationEnable     = "logger.output.file.rotation.enable"
	KeyFileRotationMaxSize    = "logger.output.file.rotation.max.size"
	KeyFileRotationMaxBackups = "logger.output.file.rotation.max.backups"
	KeyFileRotationMaxAge     = "logger.output.file.rotation.max.age"
	KeyFileRotationCompress   = "logger.output.file.rotation.compress.enable"
)

Variables

This section is empty.

Functions

func CallerPrettify added in v0.0.13

func CallerPrettify(frame *runtime.Frame) (string, string)

CallerPrettify - Prettify the caller.

func Debug added in v0.0.13

func Debug(args ...any)

func Debugf added in v0.0.13

func Debugf(format string, args ...any)

func Debugln added in v0.0.13

func Debugln(args ...any)

func Error added in v0.0.13

func Error(args ...any)

func Errorf added in v0.0.13

func Errorf(format string, args ...any)

func Errorln added in v0.0.13

func Errorln(args ...any)

func Fatal added in v0.0.13

func Fatal(args ...any)

func FatalErr added in v0.0.20

func FatalErr(err error) error

func Fatalf added in v0.0.13

func Fatalf(format string, args ...any)

func Fatalln added in v0.0.13

func Fatalln(args ...any)

func Info added in v0.0.13

func Info(args ...any)

func Infof added in v0.0.13

func Infof(format string, args ...any)

func Infoln added in v0.0.13

func Infoln(args ...any)

func NewLogger added in v0.0.7

func NewLogger(cfg *Config) *logrus.Logger

NewLogger - Create a new logger, ignore errors.

func Panic added in v0.0.13

func Panic(args ...any)

func Panicf added in v0.0.13

func Panicf(format string, args ...any)

func Panicln added in v0.0.13

func Panicln(args ...any)

func Print added in v0.0.13

func Print(args ...any)

func Printf added in v0.0.13

func Printf(format string, args ...any)

func Println added in v0.0.13

func Println(args ...any)

func Warn added in v0.0.13

func Warn(args ...any)

func Warnf added in v0.0.13

func Warnf(format string, args ...any)

func Warning added in v0.0.13

func Warning(args ...any)

func Warningf added in v0.0.13

func Warningf(format string, args ...any)

func Warningln added in v0.0.13

func Warningln(args ...any)

func Warnln added in v0.0.13

func Warnln(args ...any)

Types

type CallerHook added in v0.0.13

type CallerHook struct {
}

CallerHook - A hook to regenerate the caller field.

func (*CallerHook) Fire added in v0.0.13

func (hook *CallerHook) Fire(entry *logrus.Entry) error

func (*CallerHook) Levels added in v0.0.13

func (hook *CallerHook) Levels() []logrus.Level

type Config

type Config struct {
	Level      logrus.Level
	WithCaller bool

	// Text formatter configuration
	FormatterType            string
	FormatterTimestampEnable bool
	FormatterTimestampFormat string
	FormatterPadLevelText    bool

	// stdout output configuration.
	OutputStdoutEnable bool

	// file output configuration.
	OutputFileEnable bool
	OutputFileDir    string
	OutputFileName   string

	// file rotation configuration
	OutputFileRotationEnable     bool
	OutputFileRotationMaxSize    int
	OutputFileRotationMaxBackups int
	OutputFileRotationMaxAge     int
	OutputFileRotationCompress   bool
}
var (
	Cfg    *Config
	DefCfg = &Config{
		Level:                        logrus.InfoLevel,
		WithCaller:                   false,
		FormatterType:                "text",
		FormatterTimestampEnable:     true,
		FormatterTimestampFormat:     time.DateTime + ".000",
		FormatterPadLevelText:        true,
		OutputStdoutEnable:           true,
		OutputFileEnable:             false,
		OutputFileDir:                "/var/log/sdp",
		OutputFileName:               "sdp.log",
		OutputFileRotationEnable:     false,
		OutputFileRotationMaxSize:    100,
		OutputFileRotationMaxBackups: 3,
		OutputFileRotationMaxAge:     30,
		OutputFileRotationCompress:   false,
	}
)

Jump to

Keyboard shortcuts

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