logx

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func CopyStandardLogTo

func CopyStandardLogTo(name string)

CopyStandardLogTo arranges for messages written to the Go "log" package's default logs to also appear in the Google logs for the named and lower severities. Subsequent changes to the standard log's default output location or format may break this behavior.

Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not recognized, CopyStandardLogTo panics.

func DisableTerminal

func DisableTerminal()

DisableTerminal: 关闭屏幕打印操作

func EnableFile

func EnableFile()

EnableFile: 允许写文件

func Error

func Error(args ...interface{})

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func ErrorDepth

func ErrorDepth(depth int, args ...interface{})

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth(0, "msg") is the same as Error("msg").

func Errorf

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

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Errorln

func Errorln(args ...interface{})

Errorln logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func Exit

func Exit(args ...interface{})

Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func ExitDepth

func ExitDepth(depth int, args ...interface{})

ExitDepth acts as Exit but uses depth to determine which call frame to log. ExitDepth(0, "msg") is the same as Exit("msg").

func Exitf

func Exitf(format string, args ...interface{})

Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Exitln

func Exitln(args ...interface{})

Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).

func Fatal

func Fatal(args ...interface{})

Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func FatalDepth

func FatalDepth(depth int, args ...interface{})

FatalDepth acts as Fatal but uses depth to determine which call frame to log. FatalDepth(0, "msg") is the same as Fatal("msg").

func Fatalf

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

Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func Info

func Info(args ...interface{})

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func InfoDepth

func InfoDepth(depth int, args ...interface{})

InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth(0, "msg") is the same as Info("msg").

func Infof

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

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Infoln

func Infoln(args ...interface{})

Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func SetContentType

func SetContentType(tp MsgType)

输出日志格式为json

func SetDefault added in v1.1.0

func SetDefault(l *LoggingT)

func SetLevel

func SetLevel(level int)

func SetTrace

func SetTrace(backtrace string)

func SetVModule

func SetVModule(v string)

func Truncate

func Truncate(path string, capacity int64, f *os.File) error

Truncate changes the size of the file.

func Warning

func Warning(args ...interface{})

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func WarningDepth

func WarningDepth(depth int, args ...interface{})

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth(0, "msg") is the same as Warning("msg").

func Warningf

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

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Warningln

func Warningln(args ...interface{})

Warningln logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

Types

type DailyRotateRule

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

A DailyRotateRule is a rule to daily rotate the log files.

func (*DailyRotateRule) BackupFileName

func (r *DailyRotateRule) BackupFileName() string

BackupFileName returns the backup filename on rotating.

func (*DailyRotateRule) MarkRotated

func (r *DailyRotateRule) MarkRotated()

MarkRotated marks the rotated time of r to be the current time.

func (*DailyRotateRule) MaxSize

func (r *DailyRotateRule) MaxSize() int64

func (*DailyRotateRule) OutdatedFiles

func (r *DailyRotateRule) OutdatedFiles() []string

OutdatedFiles returns the files that exceeded the keeping days.

func (*DailyRotateRule) SetFileName

func (r *DailyRotateRule) SetFileName(fname string) bool

func (*DailyRotateRule) ShallRotate

func (r *DailyRotateRule) ShallRotate(nbytes int) bool

ShallRotate checks if the file should be rotated.

type Level

type Level int32

Level 表示输出的日志级别

type LogConf

type LogConf struct {
	ServiceName  string `json:"name,optional"`        //此日志服务名,默认为程序名。
	V            int    `json:"level,default=0"`      //此日志的全局等级,超过此等级的日志不显示和保存
	Vmodule      string `json:"vmodule,optional"`     //遵守全局V等级设置下,再按照文件设置等级,格式为 文件名=等级,此文件名不带后缀,比如 main=3
	Backtrace    string `json:"backtrace,optional"`   //追踪日志,格式为文件名:行号,比如main.go:234,此文件名带后缀
	WriteConsole bool   `json:"console,default=true"` //是否打印屏幕

	//下面的为文件相关配置
	WriteFile   bool   `json:"writefile,default=false"` //是否保存文件
	Path        string `json:"path,default=logs"`       //保存文件的目录
	Compress    bool   `json:"compress,optional"`       //日志文件备份是否zip压缩
	KeepDays    int    `json:"keepdays,optional"`       //日志文件保存天数,0表示永久保存
	MaxSize     int    `json:"maxsize,default=8388608"` //单个日志文件的最大容量,超过此值就需要切换新文件,避免单个文件过大。默认8M。
	FlushTm     int    `json:"flushtm,default=5"`       //多少秒刷新一次文件
	ContentType int64  `json:"contenttype,default=0"`   //输出日志的类型,0:默认格式 1:自定义格式 2:json格式
	TimeFormat  string `json:",optional"`               //ContentType!=0时,自定义时间戳格式 类似"2006-01-02 15:04:05.000000"
}

func NewConfig

func NewConfig() *LogConf

type LoggingT

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

LoggingT collects all the global state of the logging setup.

func NewLog

func NewLog(c *LogConf) *LoggingT

func (*LoggingT) Close

func (l *LoggingT) Close()

func (*LoggingT) DisableTerminal

func (l *LoggingT) DisableTerminal()

func (*LoggingT) EnableFile

func (l *LoggingT) EnableFile()

func (*LoggingT) Error

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

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func (*LoggingT) ErrorDepth

func (l *LoggingT) ErrorDepth(depth int, args ...interface{})

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth(0, "msg") is the same as Error("msg").

func (*LoggingT) Errorf

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

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func (*LoggingT) Errorln

func (l *LoggingT) Errorln(args ...interface{})

Errorln logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func (*LoggingT) Exit

func (l *LoggingT) Exit(args ...interface{})

Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func (*LoggingT) ExitDepth

func (l *LoggingT) ExitDepth(depth int, args ...interface{})

ExitDepth acts as Exit but uses depth to determine which call frame to log. ExitDepth(0, "msg") is the same as Exit("msg").

func (*LoggingT) Exitf

func (l *LoggingT) Exitf(format string, args ...interface{})

Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func (*LoggingT) Exitln

func (l *LoggingT) Exitln(args ...interface{})

Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).

func (*LoggingT) Fatal

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

Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func (*LoggingT) FatalDepth

func (l *LoggingT) FatalDepth(depth int, args ...interface{})

FatalDepth acts as Fatal but uses depth to determine which call frame to log. FatalDepth(0, "msg") is the same as Fatal("msg").

func (*LoggingT) Fatalf

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

Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func (*LoggingT) Fatalln

func (l *LoggingT) Fatalln(args ...interface{})

Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255). Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func (*LoggingT) Info

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

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func (*LoggingT) InfoDepth

func (l *LoggingT) InfoDepth(depth int, args ...interface{})

InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth(0, "msg") is the same as Info("msg").

func (*LoggingT) Infof

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

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func (*LoggingT) Infoln

func (l *LoggingT) Infoln(args ...interface{})

Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func (*LoggingT) SetContentType

func (l *LoggingT) SetContentType(tp MsgType) error

func (*LoggingT) SetLevel

func (l *LoggingT) SetLevel(level int)

func (*LoggingT) SetTrace

func (l *LoggingT) SetTrace(backtrace string) error

Syntax: -log_backtrace_at=gopherflakes.go:234 Note that unlike vmodule the file extension is included here.

func (*LoggingT) SetUp

func (l *LoggingT) SetUp(c *LogConf)

func (*LoggingT) SetVModule

func (l *LoggingT) SetVModule(value string) error

Syntax: -vmodule=recordio=2,file=1,gfs*=3

func (*LoggingT) V

func (l *LoggingT) V(level Level) Verbose

func (*LoggingT) Warning

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

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func (*LoggingT) WarningDepth

func (l *LoggingT) WarningDepth(depth int, args ...interface{})

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth(0, "msg") is the same as Warning("msg").

func (*LoggingT) Warningf

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

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func (*LoggingT) Warningln

func (l *LoggingT) Warningln(args ...interface{})

Warningln logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

type MsgType

type MsgType int64
const (
	MSG_DEFT MsgType = iota //默认日志格式
	MSG_SELF                //自定义格式,使用方需要自己封装日志内容
	MSG_JSON                //json日志格式

)

type RotateLogger

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

A RotateLogger is a Logger that can rotate log files with given rules.

func NewLogger

func NewLogger(sev severity, logT *LoggingT, tag string, rule RotateRule, compress bool) (*RotateLogger, error)

NewLogger returns a RotateLogger with given filename and rule, etc.

func (*RotateLogger) Close

func (l *RotateLogger) Close() error

Close closes l.

func (*RotateLogger) Sync

func (l *RotateLogger) Sync() error

func (*RotateLogger) Write

func (l *RotateLogger) Write(data []byte) (int, error)

func (*RotateLogger) WriteHeader

func (l *RotateLogger) WriteHeader()

type RotateRule

type RotateRule interface {
	BackupFileName() string
	MarkRotated()
	OutdatedFiles() []string
	ShallRotate(int) bool
	SetFileName(string) bool
	MaxSize() int64
}

A RotateRule interface is used to define the log rotating rules.

func DefaultRotateRule

func DefaultRotateRule(filename, delimiter string, opt *logOptions) RotateRule

DefaultRotateRule is a default log rotating rule, currently DailyRotateRule.

type Verbose

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

Verbose is a boolean type that implements Infof (like Printf) etc. See the documentation of V for more information.

func V

func V(level Level) Verbose

V reports whether verbosity at the call site is at least the requested level. The returned value is a boolean of type Verbose, which implements Info, Infoln and Infof. These methods will write to the Info log if called. Thus, one may write either

if glog.V(2) { glog.Info("log this") }

or

glog.V(2).Info("log this")

The second form is shorter but the first is cheaper if logging is off because it does not evaluate its arguments.

Whether an individual call to V generates a log record depends on the setting of the -v and --vmodule flags; both are off by default. If the level in the call to V is at least the value of -v, or of -vmodule for the source file containing the call, the V call will log.

func (Verbose) Info

func (v Verbose) Info(args ...interface{})

Info is equivalent to the global Info function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infof

func (v Verbose) Infof(format string, args ...interface{})

Infof is equivalent to the global Infof function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infoln

func (v Verbose) Infoln(args ...interface{})

Infoln is equivalent to the global Infoln function, guarded by the value of v. See the documentation of V for usage.

Jump to

Keyboard shortcuts

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