log

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	C_LOG_MODE        = ELM_Std          // 默认日志输出模式
	C_LOG_LEVEL       = ELL_Debug        // 默认日志过滤等级
	C_LOG_FILE_SUFFIX = "log"            // 默认日志文件后缀
	C_LOG_ROTATE_NUM  = 3                // 默认日志文件轮换数量
	C_LOG_ROTATE_SIZE = 20 * 1024 * 1024 // 默认日志文件轮换size
	C_LOG_CSIZE       = 2048             // 默认日志消息ChanSize

	C_TH_CHAN_OVERLOAD       = "Threshold:%s"    // 消息积压阀值名称
	C_TH_CHAN_OVERLOAD_VALUE = C_LOG_CSIZE * 0.8 // 消息积压阀值(过大时告警)
)
View Source
const (
	ChunkSize = 1420
)

Used to control GELF chunking. Should be less than (MTU - len(UDP header)).

TODO: generate dynamically using Path MTU Discovery?

Variables

View Source
var (
	LOG_MSG_LV_PREFIXS = [ELL_Max]string{"[TRC]", "[DBG]", "[INF]", "[WRN]", "[ERR]", "[FAL]"} // fail
	LOG_MSG_COLORS     = [ELL_Max]int{97, 94, 92, 93, 91, 95}                                  // colors
)

Functions

func Debug

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

func DebugD

func DebugD(depth int, format string, v ...interface{})

func DebugDv

func DebugDv(depth int, v ...interface{})

func Debugv

func Debugv(v ...interface{})

func Error

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

func ErrorD

func ErrorD(depth int, format string, v ...interface{})

func ErrorDv

func ErrorDv(depth int, v ...interface{})

func Errorv

func Errorv(v ...interface{})

func Fatal

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

func FatalD

func FatalD(depth int, format string, v ...interface{})

func FatalDv

func FatalDv(depth int, v ...interface{})

func Fatalv

func Fatalv(v ...interface{})

func Filter

func Filter(filter func(msg *LogUnit) bool)

Filter 设置日志过滤器

func Info

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

func InfoD

func InfoD(depth int, format string, v ...interface{})

func InfoDv

func InfoDv(depth int, v ...interface{})

func Infov

func Infov(v ...interface{})

func Init

func Init(conf *Config)

Init

func New

func New(conf *Config) *logger

func RegThreshold

func RegThreshold(name string, referValue int64, durationRate time.Duration, fmtContent string)

func Term

func Term()

Term

func Threshold

func Threshold(name string) *threshold

func Trace

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

====================

func TraceD

func TraceD(depth int, format string, v ...interface{})

func TraceDv

func TraceDv(depth int, v ...interface{})

func Tracev

func Tracev(v ...interface{})

func UseGelf

func UseGelf(conf *GraylogConf)

安装gelf拦截器,需要首先调用 Init 方法

func Warn

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

func WarnD

func WarnD(depth int, format string, v ...interface{})

func WarnDv

func WarnDv(depth int, v ...interface{})

func Warnv

func Warnv(v ...interface{})

Types

type CompressType

type CompressType int

What compression type the writer should use when sending messages to the graylog server

const (
	CompressGzip CompressType = iota
	CompressZlib
	CompressNone
)

type Config

type Config struct {
	Level      ELogLevel `json:"lv"`         // 日志等级[ELL_Debug]
	OutMode    ELogMode  `json:"mode"`       // 日志输出模式
	DirName    string    `json:"dir"`        // 输出目录[默认在程序所在目录]
	FileName   string    `json:"fileName"`   // 日志文件主名[程序本身名]
	FileSuffix string    `json:"fileSuffix"` // 日志文件后缀[log]
	RotateMax  int       `json:"rotateMax"`  // 日志文件轮换数量[3]
	RotateSize int       `json:"rotateSize"` // 日志文件轮换大小[20m]
}

日志配置

type ELogLevel

type ELogLevel int //

日志等级

const (
	ELL_Trace ELogLevel = iota
	ELL_Debug
	ELL_Infos
	ELL_Warns
	ELL_Error
	ELL_Fatal
	ELL_Max // 6
)

func GetLevel

func GetLevel() ELogLevel

GetLevel 获取系统日志当前的过滤等级

func (ELogLevel) String

func (e ELogLevel) String() string

type ELogMode

type ELogMode int //

日志输出模式

const (
	ELM_Std ELogMode = 1 << iota
	ELM_File
	ELM_Max
)

func (ELogMode) String

func (e ELogMode) String() string

type ELoggerStatus

type ELoggerStatus int //

日志运行状态

const (
	ELS_Initing ELoggerStatus = iota
	ELS_Running
	ELS_Exiting
	ELS_Stopped
	ELS_Max
)

func (ELoggerStatus) String

func (e ELoggerStatus) String() string

type GraylogConf

type GraylogConf struct {
	Address       string `json:"addr"`      // graylog地址(ip:port)
	GelfIntercept bool   `json:"intercept"` // graylog是否拦截标准输出
	Service       string `json:"service"`   // app.server.env
	WithFull      bool   `json:"withFull"`  // false
}

灰日志配置

type ILoger

type ILoger interface {

	// 添加扩展字段
	Field(field string, val interface{}) ILoger
	// 克隆ILoger对象
	Clone() ILoger

	// TRACE
	Trace(format string, v ...interface{})
	Tracev(v ...interface{})
	TraceD(depth int, format string, v ...interface{})
	TraceDv(depth int, v ...interface{})

	// DEBUG
	Debug(format string, v ...interface{})
	Debugv(v ...interface{})
	DebugD(depth int, format string, v ...interface{})
	DebugDv(depth int, v ...interface{})

	// INFO
	Info(format string, v ...interface{})
	Infov(v ...interface{})
	InfoD(depth int, format string, v ...interface{})
	InfoDv(depth int, v ...interface{})

	// WARN
	Warn(format string, v ...interface{})
	Warnv(v ...interface{})
	WarnD(depth int, format string, v ...interface{})
	WarnDv(depth int, v ...interface{})

	// ERROR
	Error(format string, v ...interface{})
	Errorv(v ...interface{})
	ErrorD(depth int, format string, v ...interface{})
	ErrorDv(depth int, v ...interface{})

	// FATAL
	Fatal(format string, v ...interface{})
	Fatalv(v ...interface{})
	FatalD(depth int, format string, v ...interface{})
	FatalDv(depth int, v ...interface{})
}

ILoger interface

func Field

func Field(field string, val interface{}) ILoger

构建字段型日志处理器<一>

func Fields

func Fields(fields map[string]interface{}) ILoger

构建字段型日志处理器<二>

type LogFields

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

自定义字段日志(带堆栈)

func (*LogFields) Clone

func (l *LogFields) Clone() ILoger

func (*LogFields) Debug

func (l *LogFields) Debug(format string, v ...interface{})

func (*LogFields) DebugD

func (l *LogFields) DebugD(depth int, format string, v ...interface{})

func (*LogFields) DebugDv

func (l *LogFields) DebugDv(depth int, v ...interface{})

func (*LogFields) Debugv

func (l *LogFields) Debugv(v ...interface{})

func (*LogFields) Error

func (l *LogFields) Error(format string, v ...interface{})

func (*LogFields) ErrorD

func (l *LogFields) ErrorD(depth int, format string, v ...interface{})

func (*LogFields) ErrorDv

func (l *LogFields) ErrorDv(depth int, v ...interface{})

func (*LogFields) Errorv

func (l *LogFields) Errorv(v ...interface{})

func (*LogFields) Fatal

func (l *LogFields) Fatal(format string, v ...interface{})

func (*LogFields) FatalD

func (l *LogFields) FatalD(depth int, format string, v ...interface{})

func (*LogFields) FatalDv

func (l *LogFields) FatalDv(depth int, v ...interface{})

func (*LogFields) Fatalv

func (l *LogFields) Fatalv(v ...interface{})

func (*LogFields) Field

func (l *LogFields) Field(field string, val interface{}) ILoger

func (*LogFields) Info

func (l *LogFields) Info(format string, v ...interface{})

func (*LogFields) InfoD

func (l *LogFields) InfoD(depth int, format string, v ...interface{})

func (*LogFields) InfoDv

func (l *LogFields) InfoDv(depth int, v ...interface{})

func (*LogFields) Infov

func (l *LogFields) Infov(v ...interface{})

func (*LogFields) Init

func (l *LogFields) Init(field string, val interface{}) ILoger

func (*LogFields) Trace

func (l *LogFields) Trace(format string, v ...interface{})

func (*LogFields) TraceD

func (l *LogFields) TraceD(depth int, format string, v ...interface{})

func (*LogFields) TraceDv

func (l *LogFields) TraceDv(depth int, v ...interface{})

func (*LogFields) Tracev

func (l *LogFields) Tracev(v ...interface{})

func (*LogFields) Warn

func (l *LogFields) Warn(format string, v ...interface{})

func (*LogFields) WarnD

func (l *LogFields) WarnD(depth int, format string, v ...interface{})

func (*LogFields) WarnDv

func (l *LogFields) WarnDv(depth int, v ...interface{})

func (*LogFields) Warnv

func (l *LogFields) Warnv(v ...interface{})

type LogUnit

type LogUnit struct {
	Lv     ELogLevel
	Str    string
	At     time.Time
	Fields map[string]interface{}
}

日志单元

type Message

type Message struct {
	Version     string                 `json:"version"`                // internal
	Host        string                 `json:"host"`                   // internal
	Short       string                 `json:"short_message"`          // internal(message field)
	Full        string                 `json:"full_message,omitempty"` // invalid
	TimeUnix    float64                `json:"timestamp"`              // 时间戳
	CreateOrder int64                  `json:"message_order"`          // 消息生产顺序
	Level       int32                  `json:"level"`                  // 日志等级
	LevelName   string                 `json:"level_name,omitempty"`   // 日志等级名称
	Facility    string                 `json:"tag,omitempty"`          // 服务名称
	MsgSize     string                 `json:"message_size,omitempty"` // 消息大小
	Extra       map[string]interface{} `json:"-"`
	RawExtra    json.RawMessage        `json:"-"` // 扩展用
}

Message represents the contents of the GELF message. It is gzipped before sending.

type Writer

type Writer struct {
	Facility         string // defaults to current process name
	CompressionLevel int    // one of the consts from compress/flate
	CompressionType  CompressType

	IncPerSecond int
	// contains filtered or unexported fields
}

Writer implements io.Writer and is used to send both discrete messages to a graylog2 server, or data from a stream-oriented interface (like the functions in log).

func (*Writer) Close

func (w *Writer) Close() error

Close connection and interrupt blocked Read or Write operations

func (*Writer) Write

func (w *Writer) Write(m *Message) (err error)

WriteMessage sends the specified message to the GELF server specified in the call to New(). It assumes all the fields are filled out appropriately. In general, clients will want to use Write, rather than WriteMessage.

Jump to

Keyboard shortcuts

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