log

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 20 Imported by: 74

Documentation

Index

Constants

View Source
const (
	DebugLevel    Level = 1
	InfoLevel           = DebugLevel<<1 + 1
	WarnLevel           = InfoLevel<<1 + 1
	ErrorLevel          = WarnLevel<<1 + 1
	FatalLevel          = ErrorLevel<<1 + 1
	CriticalLevel       = FatalLevel << +1
	ReadLevel           = InfoLevel
	UpdateLevel         = InfoLevel
)
View Source
const (
	FileNameDateFormat    = "20060102150405"
	FileOpt               = os.O_RDWR | os.O_CREATE | os.O_APPEND
	WriterBufferInitSize  = 4 * 1024 * 1024
	WriterBufferLenLimit  = 4 * 1024 * 1024
	DefaultRotateInterval = 1 * time.Second
	RotatedExtension      = ".old"
	MaxReservedDays       = 7 * 24 * time.Hour
)
View Source
const (
	InvalidLogLevel   = "Invalid log level, only support [error, warn, debug, info, read, update, critical]"
	OpenLogFileFailed = "Failed to open log file"
	GetLogNumFailed   = "Failed to get param num"
	TailLogFileFailed = "Failed to tail log file"
	InvaildLogNum     = ", invalid num param, use default num"
	TooBigNum         = ", param num is too big, use default max num"
	LossNum           = ", can't find num param, use default num"

	GetLogPath = "/log/get"
)
View Source
const (
	// DefaultRotateSize Specifies at what size to rotate the output log at
	// Units: byte
	DefaultRotateSize    = 1 * 1024 * 1024 * 1024
	DefaultMinRotateSize = 200 * 1024 * 1024
	// DefaultHeadRoom The tolerance for the log space limit (in megabytes)
	DefaultHeadRoom = 50 * 1024
	// DefaultHeadRatio The disk reserve space ratio
	DefaultHeadRatio              = 0.2
	DefaultLogLeftSpaceLimitRatio = 0.05
)
View Source
const (
	SetLogLevelPath = "/loglevel/set"
)

Variables

View Source
var (
	ErrLogFileName      = "_error.log"
	WarnLogFileName     = "_warn.log"
	InfoLogFileName     = "_info.log"
	DebugLogFileName    = "_debug.log"
	ReadLogFileName     = "_read.log"
	UpdateLogFileName   = "_write.log"
	CriticalLogFileName = "_critical.log"
	QoSLogFileName      = "_qos.log"
)
View Source
var LogDir string

Functions

func DeleteFileFilter added in v1.34.0

func DeleteFileFilter(info os.FileInfo, diskSpaceLeft int64, module string) bool

func EnableDebug added in v1.34.0

func EnableDebug() bool

func EnableInfo added in v1.34.0

func EnableInfo() bool

func GetLog added in v1.34.0

func GetLog(w http.ResponseWriter, r *http.Request)

func LogCritical added in v1.4.0

func LogCritical(v ...interface{})

LogFatal logs the fatal errors.

func LogCriticalf added in v1.4.0

func LogCriticalf(format string, v ...interface{})

LogFatalf logs the fatal errors with specified format.

func LogDebug

func LogDebug(v ...interface{})

LogDebug logs the debug information.

func LogDebugf

func LogDebugf(format string, v ...interface{})

LogDebugf logs the debug information with specified format.

func LogDisableStderrOutput added in v1.34.0

func LogDisableStderrOutput()

func LogError

func LogError(v ...interface{})

LogError logs the errors.

func LogErrorf

func LogErrorf(format string, v ...interface{})

LogErrorf logs the errors with the specified format.

func LogFatal

func LogFatal(v ...interface{})

LogFatal logs the fatal errors.

func LogFatalf

func LogFatalf(format string, v ...interface{})

LogFatalf logs the fatal errors with specified format.

func LogFlush

func LogFlush()

LogFlush flushes the log.

func LogInfo

func LogInfo(v ...interface{})

LogInfo indicates log the information. TODO explain

func LogInfof

func LogInfof(format string, v ...interface{})

LogInfo indicates log the information with specific format. TODO explain

func LogRead

func LogRead(v ...interface{})

LogRead

func LogReadf

func LogReadf(format string, v ...interface{})

TODO not used?

func LogWarn

func LogWarn(v ...interface{})

LogWarn indicates the warnings.

func LogWarnf

func LogWarnf(format string, v ...interface{})

LogWarnf indicates the warnings with specific format.

func LogWrite

func LogWrite(v ...interface{})

LogWrite

func LogWritef

func LogWritef(format string, v ...interface{})

LogWritef TODO not used

func OutputPid added in v1.34.0

func OutputPid(logDir, role string) error

func QosWrite added in v1.34.0

func QosWrite(v ...interface{})

QosWrite

func QosWriteDebugf added in v1.34.0

func QosWriteDebugf(format string, v ...interface{})

QosWriteDebugf TODO not used

func SetLogLevel added in v1.4.0

func SetLogLevel(w http.ResponseWriter, r *http.Request)

func TruncMsg added in v1.34.0

func TruncMsg(msg string) string

func TruncMsgWith added in v1.34.0

func TruncMsgWith(msg string, size int) string

Types

type HTTPReply added in v1.34.0

type HTTPReply struct {
	Code int32       `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

HTTPReply uniform response structure

type Level

type Level uint8

type Log

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

Log defines the log struct.

func InitLog

func InitLog(dir, module string, level Level, rotate *LogRotate, logLeftSpaceLimitRatio float64) (*Log, error)

InitLog initializes the log.

func (*Log) DisableStderrOutput added in v1.34.0

func (l *Log) DisableStderrOutput()

func (*Log) Flush

func (l *Log) Flush()

Flush flushes the log.

func (*Log) SetPrefix

func (l *Log) SetPrefix(s, level string) string

SetPrefix sets the log prefix.

type LogObject

type LogObject struct {
	*log.Logger
	// contains filtered or unexported fields
}

LogObject defines the log object.

func (*LogObject) Flush

func (ob *LogObject) Flush()

Flush flushes the log object.

func (*LogObject) SetRotation

func (ob *LogObject) SetRotation()

type LogRotate

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

LogRotate A log can be rotated by the size or time.

func NewLogRotate

func NewLogRotate() *LogRotate

NewLogRotate returns a new LogRotate instance.

func (*LogRotate) SetHeadRoomMb

func (r *LogRotate) SetHeadRoomMb(size int64)

SetHeadRoomMb sets the headroom in terms of MB.

func (*LogRotate) SetRotateSizeMb added in v1.34.0

func (r *LogRotate) SetRotateSizeMb(size int64)

SetRotateSizeMb sets the rotate size in terms of MB.

type RotatedFile added in v1.34.0

type RotatedFile []os.FileInfo

func (RotatedFile) Len added in v1.34.0

func (f RotatedFile) Len() int

func (RotatedFile) Less added in v1.34.0

func (f RotatedFile) Less(i, j int) bool

func (RotatedFile) Swap added in v1.34.0

func (f RotatedFile) Swap(i, j int)

Jump to

Keyboard shortcuts

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