glog

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package glog implements powerful and easy-to-use levelled logging functionality.

Index

Constants

View Source
const (
	LEVEL_ALL  = LEVEL_DEBU | LEVEL_INFO | LEVEL_NOTI | LEVEL_WARN | LEVEL_ERRO | LEVEL_CRIT
	LEVEL_DEV  = LEVEL_ALL
	LEVEL_PROD = LEVEL_WARN | LEVEL_ERRO | LEVEL_CRIT
	LEVEL_DEBU = 1 << iota
	LEVEL_INFO
	LEVEL_NOTI
	LEVEL_WARN
	LEVEL_ERRO
	LEVEL_CRIT
)
View Source
const (
	F_ASYNC      = 1 << iota // Print logging content asynchronously。
	F_FILE_LONG              // Print full file name and line number: /a/b/c/d.go:23.
	F_FILE_SHORT             // Print final file name element and line number: d.go:23. overrides F_FILE_LONG.
	F_TIME_DATE              // Print the date in the local time zone: 2009-01-23.
	F_TIME_TIME              // Print the time in the local time zone: 01:23:23.
	F_TIME_MILLI             // Print the time with milliseconds in the local time zone: 01:23:23.675.
	F_TIME_STD   = F_TIME_DATE | F_TIME_MILLI
)

Variables

This section is empty.

Functions

func Critical

func Critical(v ...interface{})

Critical prints the logging content with [CRIT] header and newline. It also prints caller stack info if stack feature is enabled.

func Criticalf

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

Criticalf prints the logging content with [CRIT] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func Criticalfln

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

Deprecated. Use Criticalf instead.

func Debug

func Debug(v ...interface{})

Debug prints the logging content with [DEBU] header and newline.

func Debugf

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

Debugf prints the logging content with [DEBU] header, custom format and newline.

func Debugfln

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

Deprecated. Use Debugf instead.

func Error

func Error(v ...interface{})

Error prints the logging content with [ERRO] header and newline. It also prints caller stack info if stack feature is enabled.

func Errorf

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

Errorf prints the logging content with [ERRO] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func Errorfln

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

Deprecated. Use Errorf instead.

func Fatal

func Fatal(v ...interface{})

Fatal prints the logging content with [FATA] header and newline, then exit the current process.

func Fatalf

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

Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.

func Fatalfln

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

Deprecated. Use Fatalf instead.

func GetFlags

func GetFlags() int

GetFlags returns the flags of logger.

func GetLevel

func GetLevel() int

GetLevel returns the default logging level value.

func GetPath

func GetPath() string

GetPath returns the logging directory path for file logging. It returns empty string if no directory path set.

func GetStack

func GetStack(skip ...int) string

GetStack returns the caller stack content, the optional parameter <skip> specify the skipped stack offset from the end point.

func GetWriter

func GetWriter() io.Writer

GetWriter returns the customized writer object, which implements the io.Writer interface. It returns nil if no customized writer set.

func Info

func Info(v ...interface{})

Info prints the logging content with [INFO] header and newline.

func Infof

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

Infof prints the logging content with [INFO] header, custom format and newline.

func Infofln

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

Deprecated. Use Infof instead.

func Notice

func Notice(v ...interface{})

Notice prints the logging content with [NOTI] header and newline. It also prints caller stack info if stack feature is enabled.

func Noticef

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

Noticef prints the logging content with [NOTI] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func Noticefln

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

Deprecated. Use Noticef instead.

func Panic

func Panic(v ...interface{})

Panic prints the logging content with [PANI] header and newline, then panics.

func Panicf

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

Panicf prints the logging content with [PANI] header, custom format and newline, then panics.

func Panicfln

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

Deprecated. Use Panicf instead.

func Print

func Print(v ...interface{})

Print prints <v> with newline using fmt.Sprintln. The parameter <v> can be multiple variables.

func PrintStack

func PrintStack(skip ...int)

PrintStack prints the caller stack, the optional parameter <skip> specify the skipped stack offset from the end point.

func Printf

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

Printf prints <v> with format <format> using fmt.Sprintf. The parameter <v> can be multiple variables.

func Printfln

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

Deprecated. Use Printf instead.

func Println

func Println(v ...interface{})

See Print.

func SetAsync

func SetAsync(enabled bool)

SetAsync enables/disables async logging output feature for default logger.

func SetDebug

func SetDebug(debug bool)

SetDebug enables/disables the debug level for default logger. The debug level is enbaled in default.

func SetFile

func SetFile(pattern string)

SetFile sets the file name <pattern> for file logging. Datetime pattern can be used in <pattern>, eg: access-{Ymd}.log. The default file name pattern is: Y-m-d.log, eg: 2018-01-01.log

func SetFlags

func SetFlags(flags int)

SetFlags sets extra flags for logging output features.

func SetHeaderPrint

func SetHeaderPrint(enabled bool)

SetHeaderPrint sets whether output header of the logging contents, which is true in default.

func SetLevel

func SetLevel(level int)

SetLevel sets the default logging level.

func SetPath

func SetPath(path string) error

SetPath sets the directory path for file logging.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets prefix string for every logging content. Prefix is part of header, which means if header output is shut, no prefix will be output.

func SetStack

func SetStack(enabled bool)

SetStack enables/disables the stack feature in failure logging outputs.

func SetStdoutPrint

func SetStdoutPrint(enabled bool)

SetStdoutPrint sets whether ouptput the logging contents to stdout, which is true in default.

func SetWriter

func SetWriter(writer io.Writer)

SetWriter sets the customized logging <writer> for logging. The <writer> object should implements the io.Writer interface. Developer can use customized logging <writer> to redirect logging output to another service, eg: kafka, mysql, mongodb, etc.

func Warning

func Warning(v ...interface{})

Warning prints the logging content with [WARN] header and newline. It also prints caller stack info if stack feature is enabled.

func Warningf

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

Warningf prints the logging content with [WARN] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func Warningfln

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

Deprecated. Use Warningf instead.

Types

type Logger

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

func Async

func Async(enabled ...bool) *Logger

Async is a chaining function, which enables/disables async logging output feature.

func Cat

func Cat(category string) *Logger

Cat is a chaining function, which sets the category to <category> for current logging content output.

func Expose

func Expose() *Logger

Expose returns the default logger of glog.

func File

func File(pattern string) *Logger

File is a chaining function, which sets file name <pattern> for the current logging content output.

func Header(enabled ...bool) *Logger

Header is a chaining function, which enables/disables log header for the current logging content output. It's enabled in default.

func Level

func Level(level int) *Logger

Level is a chaining function, which sets logging level for the current logging content output.

func Line

func Line(long ...bool) *Logger

Line is a chaining function, which enables/disables printing its caller file along with its line number. The parameter <long> specified whether print the long absolute file path, eg: /a/b/c/d.go:23.

func New

func New() *Logger

New creates and returns a custom logger.

func Path

func Path(path string) *Logger

Path is a chaining function, which sets the directory path to <path> for current logging content output.

func Skip

func Skip(skip int) *Logger

Skip is a chaining function, which sets stack skip for the current logging content output. It also affects the caller file path checks when line number printing enabled.

func Stack

func Stack(enabled bool, skip ...int) *Logger

Stack is a chaining function, which sets stack options for the current logging content output .

func Stdout

func Stdout(enabled ...bool) *Logger

StdPrint is a chaining function, which enables/disables stdout for the current logging content output. It's enabled in default.

func To

func To(writer io.Writer) *Logger

To is a chaining function, which redirects current logging content output to the sepecified <writer>.

func (*Logger) Async

func (l *Logger) Async(enabled ...bool) *Logger

Async is a chaining function, which enables/disables async logging output feature.

func (*Logger) Cat

func (l *Logger) Cat(category string) *Logger

Cat is a chaining function, which sets the category to <category> for current logging content output. Param <category> can be hierarchical, eg: module/user.

func (*Logger) Clone

func (l *Logger) Clone() *Logger

Clone returns a new logger, which is the clone the current logger.

func (*Logger) Critical

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

Critical prints the logging content with [CRIT] header and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Criticalf

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

Criticalf prints the logging content with [CRIT] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Criticalfln

func (l *Logger) Criticalfln(format string, v ...interface{})

Deprecated. Use Criticalf instead.

func (*Logger) Debug

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

Debug prints the logging content with [DEBU] header and newline.

func (*Logger) Debugf

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

Debugf prints the logging content with [DEBU] header, custom format and newline.

func (*Logger) Debugfln

func (l *Logger) Debugfln(format string, v ...interface{})

Deprecated. Use Debugf instead.

func (*Logger) Error

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

Error prints the logging content with [ERRO] header and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Errorf

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

Errorf prints the logging content with [ERRO] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Errorfln

func (l *Logger) Errorfln(format string, v ...interface{})

Deprecated. Use Errorf instead.

func (*Logger) Fatal

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

Fatal prints the logging content with [FATA] header and newline, then exit the current process.

func (*Logger) Fatalf

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

Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.

func (*Logger) Fatalfln

func (l *Logger) Fatalfln(format string, v ...interface{})

Deprecated. Use Fatalf instead.

func (*Logger) File

func (l *Logger) File(file string) *Logger

File is a chaining function, which sets file name <pattern> for the current logging content output.

func (*Logger) GetFlags

func (l *Logger) GetFlags() int

GetFlags returns the flags of logger.

func (*Logger) GetLevel

func (l *Logger) GetLevel() int

GetLevel returns the logging level value.

func (*Logger) GetPath

func (l *Logger) GetPath() string

GetPath returns the logging directory path for file logging. It returns empty string if no directory path set.

func (*Logger) GetStack

func (l *Logger) GetStack(skip ...int) string

GetStack returns the caller stack content, the optional parameter <skip> specify the skipped stack offset from the end point.

func (*Logger) GetWriter

func (l *Logger) GetWriter() io.Writer

GetWriter returns the customized writer object, which implements the io.Writer interface. It returns nil if no writer previously set.

func (*Logger) Header

func (l *Logger) Header(enabled ...bool) *Logger

Header is a chaining function, which enables/disables log header for the current logging content output. It's enabled in default.

func (*Logger) Info

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

Info prints the logging content with [INFO] header and newline.

func (*Logger) Infof

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

Infof prints the logging content with [INFO] header, custom format and newline.

func (*Logger) Infofln

func (l *Logger) Infofln(format string, v ...interface{})

Deprecated. Use Infof instead.

func (*Logger) Level

func (l *Logger) Level(level int) *Logger

Level is a chaining function, which sets logging level for the current logging content output.

func (*Logger) Line

func (l *Logger) Line(long ...bool) *Logger

Line is a chaining function, which enables/disables printing its caller file path along with its line number. The parameter <long> specified whether print the long absolute file path, eg: /a/b/c/d.go:23, or else short one: d.go:23.

func (*Logger) Notice

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

Notice prints the logging content with [NOTI] header and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Noticef

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

Noticef prints the logging content with [NOTI] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Noticefln

func (l *Logger) Noticefln(format string, v ...interface{})

Deprecated. Use Noticef instead.

func (*Logger) Panic

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

Panic prints the logging content with [PANI] header and newline, then panics.

func (*Logger) Panicf

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

Panicf prints the logging content with [PANI] header, custom format and newline, then panics.

func (*Logger) Panicfln

func (l *Logger) Panicfln(format string, v ...interface{})

Deprecated. Use Panicf instead.

func (*Logger) Path

func (l *Logger) Path(path string) *Logger

Path is a chaining function, which sets the directory path to <path> for current logging content output.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print prints <v> with newline using fmt.Sprintln. The parameter <v> can be multiple variables.

func (*Logger) PrintStack

func (l *Logger) PrintStack(skip ...int)

PrintStack prints the caller stack, the optional parameter <skip> specify the skipped stack offset from the end point.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf prints <v> with format <format> using fmt.Sprintf. The parameter <v> can be multiple variables.

func (*Logger) Printfln

func (l *Logger) Printfln(format string, v ...interface{})

Deprecated. Use Printf instead.

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

See Print.

func (*Logger) SetAsync

func (l *Logger) SetAsync(enabled bool)

SetAsync enables/disables async logging output feature.

func (*Logger) SetDebug

func (l *Logger) SetDebug(debug bool)

SetDebug enables/disables the debug level for logger. The debug level is enabled in default.

func (*Logger) SetFile

func (l *Logger) SetFile(pattern string)

SetFile sets the file name <pattern> for file logging. Datetime pattern can be used in <pattern>, eg: access-{Ymd}.log. The default file name pattern is: Y-m-d.log, eg: 2018-01-01.log

func (*Logger) SetFlags

func (l *Logger) SetFlags(flags int)

SetFlags sets extra flags for logging output features.

func (*Logger) SetHeaderPrint

func (l *Logger) SetHeaderPrint(enabled bool)

SetHeaderPrint sets whether output header of the logging contents, which is true in default.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel sets the logging level.

func (*Logger) SetPath

func (l *Logger) SetPath(path string) error

SetPath sets the directory path for file logging.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets prefix string for every logging content. Prefix is part of header, which means if header output is shut, no prefix will be output.

func (*Logger) SetStack

func (l *Logger) SetStack(enabled bool)

SetStack enables/disables the stack feature in failure logging outputs.

func (*Logger) SetStackSkip

func (l *Logger) SetStackSkip(skip int)

SetStackSkip sets the stack offset from the end point.

func (*Logger) SetStdoutPrint

func (l *Logger) SetStdoutPrint(enabled bool)

SetStdoutPrint sets whether output the logging contents to stdout, which is true in default.

func (*Logger) SetWriter

func (l *Logger) SetWriter(writer io.Writer)

SetWriter sets the customized logging <writer> for logging. The <writer> object should implements the io.Writer interface. Developer can use customized logging <writer> to redirect logging output to another service, eg: kafka, mysql, mongodb, etc.

func (*Logger) Skip

func (l *Logger) Skip(skip int) *Logger

Skip is a chaining function, which sets stack skip for the current logging content output. It also affects the caller file path checks when line number printing enabled.

func (*Logger) Stack

func (l *Logger) Stack(enabled bool, skip ...int) *Logger

Stack is a chaining function, which sets stack options for the current logging content output .

func (*Logger) StdPrint

func (l *Logger) StdPrint(enabled ...bool) *Logger

See Stdout. Deprecated.

func (*Logger) Stdout

func (l *Logger) Stdout(enabled ...bool) *Logger

Stdout is a chaining function, which enables/disables stdout for the current logging content output. It's enabled in default.

func (*Logger) To

func (l *Logger) To(writer io.Writer) *Logger

To is a chaining function, which redirects current logging content output to the specified <writer>.

func (*Logger) Warning

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

Warning prints the logging content with [WARN] header and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Warningf

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

Warningf prints the logging content with [WARN] header, custom format and newline. It also prints caller stack info if stack feature is enabled.

func (*Logger) Warningfln

func (l *Logger) Warningfln(format string, v ...interface{})

Deprecated. Use Warningf instead.

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. It just prints the content using Print.

Jump to

Keyboard shortcuts

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