logger

package
v1.6.65 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LOG_ROTATION_INTERVAL = 24 * time.Hour       // every day
	LOG_MAX_AGE           = 365 * 24 * time.Hour // every year
	LOG_FORMAT            = "%{time:2006-01-02 15:04:05.000} [%{level:.4s}] [%{module}] %{shortfile} %{message}"
	LOG_COLOR_FORMAT      = "%{color}%{time:2006-01-02 15:04:05.000} [%{level:.4s}]%{color:reset} [%{module}] %{shortfile} %{message}"
	SYSLOG_FORMAT         = "[%{level:.4s}] %{shortfile} %{message}"
)
View Source
const (
	SYSLOG_PRIORITY = syslog.LOG_CRIT | syslog.LOG_DAEMON
)

Variables

This section is empty.

Functions

func EnableCustomBackends

func EnableCustomBackends(backends ...ClosableBackend)

func EnableFileLog

func EnableFileLog(logPath string) error

func EnableFileLogWithMaxAge

func EnableFileLogWithMaxAge(logPath string, maxAge time.Duration) error

func EnableRsyslog

func EnableRsyslog(msgType byte, remotePort int, remotes ...string) error

msgType在datatype/droplet-message.go中定义 trident调用时前2个参数传入datatype.MESSAGE_TYPE_SYSLOG 和 30033

func EnableStdoutLog

func EnableStdoutLog()

func EnableSyslog

func EnableSyslog() error

func GinLogFormat

func GinLogFormat(param gin.LogFormatterParams) string

func RsyslogSetHostname

func RsyslogSetHostname(value string)

func RsyslogSetThreshold

func RsyslogSetThreshold(value uint32)

Types

type ClosableBackend

type ClosableBackend interface {
	logging.Backend
	io.Closer
}

type Logger

type Logger struct {
	*logging.Logger
}

Logger is a wrapper around go-logging.Logger. It adds support for logging with flexible prefixes. Prefixes should implement the Prefix interface. The Logger will automatically extract the prefixes from the arguments and prepend them to the log message ordered by the order of the arguments. Prefixes must be placed at the end of the arguments list. Example:

// logger is a *Logger, ORGPrefix is the struct which implements Prefix interface and returns the organization ID information.
logger.Info("message", ORGPrefix(2))

will log: "[ORGID-2] message"

func MustGetLogger

func MustGetLogger(module string) *Logger

func (*Logger) Critical

func (l *Logger) Critical(args ...interface{})

func (*Logger) Criticalf

func (l *Logger) Criticalf(format string, args ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) Notice

func (l *Logger) Notice(args ...interface{})

func (*Logger) Noticef

func (l *Logger) Noticef(format string, args ...interface{})

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{})

func (*Logger) Warning

func (l *Logger) Warning(args ...interface{})

func (*Logger) Warningf

func (l *Logger) Warningf(format string, args ...interface{})

type ORGPrefix

type ORGPrefix int

ORGPrefix implements LogPrefix to provide a prefix for log messages with an organization ID.

func (ORGPrefix) Prefix

func (o ORGPrefix) Prefix() string

type Prefix

type Prefix interface {
	// Prefix returns the prefix string.
	Prefix() string
}

Prefix is an interface that can be implemented by types that want to provide a prefix to a log message.

func NewORGPrefix

func NewORGPrefix(id int) Prefix

func NewTeamPrefix

func NewTeamPrefix(id int) Prefix

type PrefixLogger

type PrefixLogger struct {
	*logging.Logger
	// contains filtered or unexported fields
}

func GetPrefixLogger

func GetPrefixLogger(module, prefix string) (*PrefixLogger, error)

func WrapWithPrefixLogger

func WrapWithPrefixLogger(prefix string, logger *logging.Logger) *PrefixLogger

将logger包装为前缀logger 注意需要自行将ExtraCalldepth加1,以便拿到log文件名,行号等信息

func (*PrefixLogger) Critical

func (l *PrefixLogger) Critical(args ...interface{})

func (*PrefixLogger) Criticalf

func (l *PrefixLogger) Criticalf(format string, args ...interface{})

func (*PrefixLogger) Debug

func (l *PrefixLogger) Debug(args ...interface{})

func (*PrefixLogger) Debugf

func (l *PrefixLogger) Debugf(format string, args ...interface{})

func (*PrefixLogger) Error

func (l *PrefixLogger) Error(args ...interface{})

func (*PrefixLogger) Errorf

func (l *PrefixLogger) Errorf(format string, args ...interface{})

func (*PrefixLogger) Fatal

func (l *PrefixLogger) Fatal(args ...interface{})

func (*PrefixLogger) Fatalf

func (l *PrefixLogger) Fatalf(format string, args ...interface{})

func (*PrefixLogger) GetPrefix

func (l *PrefixLogger) GetPrefix() string

func (*PrefixLogger) Info

func (l *PrefixLogger) Info(args ...interface{})

func (*PrefixLogger) Infof

func (l *PrefixLogger) Infof(format string, args ...interface{})

func (*PrefixLogger) Notice

func (l *PrefixLogger) Notice(args ...interface{})

func (*PrefixLogger) Noticef

func (l *PrefixLogger) Noticef(format string, args ...interface{})

func (*PrefixLogger) Panic

func (l *PrefixLogger) Panic(args ...interface{})

func (*PrefixLogger) Panicf

func (l *PrefixLogger) Panicf(format string, args ...interface{})

func (*PrefixLogger) UpdatePrefix

func (l *PrefixLogger) UpdatePrefix(prefix string)

func (*PrefixLogger) Warning

func (l *PrefixLogger) Warning(args ...interface{})

func (*PrefixLogger) Warningf

func (l *PrefixLogger) Warningf(format string, args ...interface{})

type RSyslogWriter

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

func NewRsyslogWriter

func NewRsyslogWriter(network, raddr string, tag, header string) *RSyslogWriter

func (*RSyslogWriter) Close

func (w *RSyslogWriter) Close() error

Close closes a connection to the syslog daemon.

func (*RSyslogWriter) SetHostname

func (w *RSyslogWriter) SetHostname(value string)

func (*RSyslogWriter) SetThreshold

func (w *RSyslogWriter) SetThreshold(value uint32)

func (*RSyslogWriter) Write

func (w *RSyslogWriter) Write(b []byte) (int, error)

Write sends a log message to the syslog daemon.

type TeamPrefix

type TeamPrefix int

func (TeamPrefix) Prefix

func (t TeamPrefix) Prefix() string

Directories

Path Synopsis
blocker module

Jump to

Keyboard shortcuts

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