xlog

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NOTSET  = iota
	DEBUG   = LogLevel(10 * iota) // DEBUG = 10
	INFO    = LogLevel(10 * iota) // INFO = 20
	WARNING = LogLevel(10 * iota) // WARNING = 30
	ERROR   = LogLevel(10 * iota) // ERROR = 40
)

MessageLevel

Variables

View Source
var LevelString = map[LogLevel]string{
	DEBUG:   "DEBUG",
	INFO:    "INFO",
	WARNING: consolecolors.Yellow("WARNING"),
	ERROR:   consolecolors.Red("ERROR"),
}
View Source
var LoggerDefaultDateFormat = "2006/01/02 15:04:05.00"

Functions

This section is empty.

Types

type ColorScheme

type ColorScheme struct {
	InfoLevelStyle  string
	WarnLevelStyle  string
	ErrorLevelStyle string
	FatalLevelStyle string
	PanicLevelStyle string
	DebugLevelStyle string
	PrefixStyle     string
	TimestampStyle  string
}

type HourlySplit added in v1.9.4

type HourlySplit struct {
	Dir        string // path of log file directory
	FileFormat string // log_2006-01-02T15
	// MaxFileNumber is max file number, auto delete old file if limit exceed.
	// treat as not limit if set to 0.
	MaxFileNumber int64
	// max disk ussage, auto delete old file if limit exceed.
	// It is a soft limit - we do not change every time the Write() be called,
	// we check only when file spliting.
	// 0 means not limit.
	MaxDiskUsage int64
	// contains filtered or unexported fields
}

HourlySplit split outer file hourly

func (*HourlySplit) Close added in v1.9.4

func (a *HourlySplit) Close() error

Close close all file discriptor

func (*HourlySplit) Write added in v1.9.4

func (a *HourlySplit) Write(b []byte) (n int, err error)

Write implement writer

type ILogger

type ILogger interface {
	SetClass(className string)

	Debug(format string, a ...interface{})
	Info(format string, a ...interface{})
	Warning(format string, a ...interface{})
	Error(format string, a ...interface{})

	SetCustomLogFormat(logFormatterFunc func(logInfo interface{}) string)
	SetDateFormat(format string)
}

func GetClassLogger

func GetClassLogger(class string, options *LogOptions) ILogger

func GetXLogger

func GetXLogger(class string) ILogger

func GetXLoggerWith

func GetXLoggerWith(logger ILogger) ILogger

func GetXLoggerWithFields

func GetXLoggerWithFields(class string, fields map[string]interface{}) ILogger

func NewLogger

func NewLogger(options *LogOptions) ILogger

type LogInfo

type LogInfo struct {
	StartTime string
	Level     string
	Class     string
	Host      string
	Message   string
	Extend    map[string]interface{}
}

type LogLevel

type LogLevel int

type LogOptions added in v1.9.5

type LogOptions struct {
	LogPath         string `mapstructure:"log_path"`
	LogLevel        string `mapstructure:"log_level"` // trace, debug, info, warn[ing], error, fatal, panic
	LogMaxDiskUsage int64  `mapstructure:"log_max_disk_usage"`
	LogMaxFileNum   int    `mapstructure:"log_max_file_num"`
	AppName         string `mapstructure:"app_name"`
}

type LogrusLogger

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

func (LogrusLogger) Debug

func (log LogrusLogger) Debug(format string, a ...interface{})

func (LogrusLogger) Error

func (log LogrusLogger) Error(format string, a ...interface{})

func (LogrusLogger) Info

func (log LogrusLogger) Info(format string, a ...interface{})

func (*LogrusLogger) SetClass

func (log *LogrusLogger) SetClass(className string)

func (*LogrusLogger) SetCustomLogFormat

func (log *LogrusLogger) SetCustomLogFormat(logFormatterFunc func(logInfo interface{}) string)

func (LogrusLogger) SetDateFormat

func (log LogrusLogger) SetDateFormat(format string)

func (LogrusLogger) Warning

func (log LogrusLogger) Warning(format string, a ...interface{})

func (*LogrusLogger) With

func (log *LogrusLogger) With(level LogLevel, fiedls map[string]interface{}) *logrus.Entry

type TextFormatter

type TextFormatter struct {
	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool

	// Force disabling colors. For a TTY colors are enabled by default.
	DisableColors bool

	// Force formatted layout, even for non-TTY output.
	ForceFormatting bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Disable the conversion of the log levels to uppercase
	DisableUppercase bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// Timestamp format to use for display when a full timestamp is printed.
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	// Wrap empty fields in quotes if true.
	QuoteEmptyFields bool

	// Can be set to the override the default quoting character "
	// with something else. For example: ', or `.
	QuoteCharacter string

	// Pad msg field with spaces on the right for display.
	// The value for this parameter will be the size of padding.
	// Its default value is zero, which means no padding will be applied for msg.
	SpacePadding int

	sync.Once
	// contains filtered or unexported fields
}

func (*TextFormatter) Format

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

func (*TextFormatter) SetColorScheme

func (f *TextFormatter) SetColorScheme(colorScheme *ColorScheme)

type XDefaultLogger

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

func NewLoggerWith

func NewLoggerWith(log *log.Logger) *XDefaultLogger

func NewXLogger

func NewXLogger() *XDefaultLogger

func (*XDefaultLogger) Debug

func (log *XDefaultLogger) Debug(format string, a ...interface{})

func (*XDefaultLogger) Error

func (log *XDefaultLogger) Error(format string, a ...interface{})

func (*XDefaultLogger) Info

func (log *XDefaultLogger) Info(format string, a ...interface{})

func (*XDefaultLogger) SetClass

func (log *XDefaultLogger) SetClass(className string)

func (*XDefaultLogger) SetCustomLogFormat

func (log *XDefaultLogger) SetCustomLogFormat(logFormatterFunc func(logInfo interface{}) string)

func (*XDefaultLogger) SetDateFormat

func (log *XDefaultLogger) SetDateFormat(format string)

func (*XDefaultLogger) Warning

func (log *XDefaultLogger) Warning(format string, a ...interface{})

Jump to

Keyboard shortcuts

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