Documentation ¶
Overview ¶
Package glog implements powerful and easy-to-use levelled logging functionality.
Index ¶
- Constants
- func Critical(v ...interface{})
- func Criticalf(format string, v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func GetFlags() int
- func GetLevel() int
- func GetPath() string
- func GetStack(skip ...int) string
- func GetWriter() io.Writer
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Notice(v ...interface{})
- func Noticef(format string, v ...interface{})
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Print(v ...interface{})
- func PrintStack(skip ...int)
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetAsync(enabled bool)
- func SetConfig(config Config) error
- func SetConfigWithMap(m map[string]interface{}) error
- func SetDebug(debug bool)
- func SetDefaultLogger(l *Logger)
- func SetFile(pattern string)
- func SetFlags(flags int)
- func SetHeaderPrint(enabled bool)
- func SetLevel(level int)
- func SetPath(path string) error
- func SetPrefix(prefix string)
- func SetStack(enabled bool)
- func SetStdoutPrint(enabled bool)
- func SetWriter(writer io.Writer)
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- type Config
- type Logger
- func Async(enabled ...bool) *Logger
- func Cat(category string) *Logger
- func DefaultLogger() *Logger
- func Expose() *Logger
- func File(pattern string) *Logger
- func Header(enabled ...bool) *Logger
- func Instance(name ...string) *Logger
- func Level(level int) *Logger
- func Line(long ...bool) *Logger
- func New() *Logger
- func NewWithWriter(writer io.Writer) *Logger
- func Path(path string) *Logger
- func Skip(skip int) *Logger
- func Stack(enabled bool, skip ...int) *Logger
- func StackWithFilter(filter string) *Logger
- func Stdout(enabled ...bool) *Logger
- func To(writer io.Writer) *Logger
- func (l *Logger) Async(enabled ...bool) *Logger
- func (l *Logger) Cat(category string) *Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) Critical(v ...interface{})
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) File(file string) *Logger
- func (l *Logger) GetFlags() int
- func (l *Logger) GetLevel() int
- func (l *Logger) GetLevelPrefix(level int) string
- func (l *Logger) GetPath() string
- func (l *Logger) GetStack(skip ...int) string
- func (l *Logger) GetWriter() io.Writer
- func (l *Logger) Header(enabled ...bool) *Logger
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Level(level int) *Logger
- func (l *Logger) Line(long ...bool) *Logger
- func (l *Logger) Notice(v ...interface{})
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Path(path string) *Logger
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) PrintStack(skip ...int)
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) SetAsync(enabled bool)
- func (l *Logger) SetConfig(config Config) error
- func (l *Logger) SetConfigWithMap(m map[string]interface{}) error
- func (l *Logger) SetDebug(debug bool)
- func (l *Logger) SetFile(pattern string)
- func (l *Logger) SetFlags(flags int)
- func (l *Logger) SetHeaderPrint(enabled bool)
- func (l *Logger) SetLevel(level int)
- func (l *Logger) SetLevelPrefix(level int, prefix string)
- func (l *Logger) SetLevelPrefixes(prefixes map[int]string)
- func (l *Logger) SetPath(path string) error
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) SetStack(enabled bool)
- func (l *Logger) SetStackFilter(filter string)
- func (l *Logger) SetStackSkip(skip int)
- func (l *Logger) SetStdoutPrint(enabled bool)
- func (l *Logger) SetWriter(writer io.Writer)
- func (l *Logger) Skip(skip int) *Logger
- func (l *Logger) Stack(enabled bool, skip ...int) *Logger
- func (l *Logger) StackWithFilter(filter string) *Logger
- func (l *Logger) Stdout(enabled ...bool) *Logger
- func (l *Logger) To(writer io.Writer) *Logger
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Write(p []byte) (n int, err error)
Constants ¶
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 )
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 // 8 LEVEL_INFO // 16 LEVEL_NOTI // 32 LEVEL_WARN // 64 LEVEL_ERRO // 128 LEVEL_CRIT // 256 LEVEL_PANI // 512 LEVEL_FATA // 1024 )
Note that the LEVEL_PANI and LEVEL_FATA levels are not used for logging output, but for prefix configurations.
const (
// Default group name for instance usage.
DEFAULT_NAME = "default"
)
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 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 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 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 GetPath ¶
func GetPath() string
GetPath returns the logging directory path for file logging. It returns empty string if no directory path set.
func GetStack ¶
GetStack returns the caller stack content, the optional parameter <skip> specify the skipped stack offset from the end point.
func GetWriter ¶
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 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 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 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 SetAsync ¶
func SetAsync(enabled bool)
SetAsync enables/disables async logging output feature for default logger.
func SetConfigWithMap ¶ added in v1.10.0
SetConfigWithMap set configurations with map for the logger.
func SetDebug ¶
func SetDebug(debug bool)
SetDebug enables/disables the debug level for default logger. The debug level is enbaled in default.
func SetDefaultLogger ¶ added in v1.11.5
func SetDefaultLogger(l *Logger)
SetDefaultLogger sets the default logger for package glog. Note that there might be concurrent safety issue if calls this function in different goroutines.
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 SetHeaderPrint ¶
func SetHeaderPrint(enabled bool)
SetHeaderPrint sets whether output header of the logging contents, which is true in default.
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 ¶
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.
Types ¶
type Config ¶ added in v1.10.0
type Config struct { Writer io.Writer // Customized io.Writer. Flags int // Extra flags for logging output features. Path string // Logging directory path. File string // Format for logging file. Level int // Output level. Prefix string // Prefix string for every logging content. StSkip int // Skip count for stack. StStatus int // Stack status(1: enabled - default; 0: disabled) StFilter string // Stack string filter. HeaderPrint bool `c:"header"` // Print header or not(true in default). StdoutPrint bool `c:"stdout"` // Output to stdout or not(true in default). LevelPrefixes map[int]string // Logging level to its prefix string mapping. }
Config is the configuration object for logger.
func DefaultConfig ¶ added in v1.10.0
func DefaultConfig() Config
DefaultConfig returns the default configuration for logger.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the struct for logging management.
func Cat ¶
Cat is a chaining function, which sets the category to <category> for current logging content output.
func DefaultLogger ¶ added in v1.10.0
func DefaultLogger() *Logger
Default returns the default logger.
func File ¶
File is a chaining function, which sets file name <pattern> for the current logging content output.
func Header ¶
Header is a chaining function, which enables/disables log header for the current logging content output. It's enabled in default.
func Instance ¶ added in v1.10.0
Instance returns an instance of Logger with default settings. The parameter <name> is the name for the instance.
func Level ¶
Level is a chaining function, which sets logging level for the current logging content output.
func Line ¶
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 NewWithWriter ¶ added in v1.11.5
NewWithWriter creates and returns a custom logger with io.Writer.
func Path ¶
Path is a chaining function, which sets the directory path to <path> for current logging content output.
func Skip ¶
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 ¶
Stack is a chaining function, which sets stack options for the current logging content output .
func StackWithFilter ¶
StackWithFilter is a chaining function, which sets stack filter for the current logging content output .
func Stdout ¶
StdPrint is a chaining function, which enables/disables stdout for the current logging content output. It's enabled in default.
func To ¶
To is a chaining function, which redirects current logging content output to the sepecified <writer>.
func (*Logger) Async ¶
Async is a chaining function, which enables/disables async logging output feature.
func (*Logger) Cat ¶
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) 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 ¶
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) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug prints the logging content with [DEBU] header and newline.
func (*Logger) Debugf ¶
Debugf prints the logging content with [DEBU] header, custom format and newline.
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 ¶
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) 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 ¶
Fatalf prints the logging content with [FATA] header, custom format and newline, then exit the current process.
func (*Logger) File ¶
File is a chaining function, which sets file name <pattern> for the current logging content output.
func (*Logger) GetLevelPrefix ¶ added in v1.11.5
GetLevelPrefix returns the prefix string for specified level.
func (*Logger) GetPath ¶
GetPath returns the logging directory path for file logging. It returns empty string if no directory path set.
func (*Logger) GetStack ¶
GetStack returns the caller stack content, the optional parameter <skip> specify the skipped stack offset from the end point.
func (*Logger) GetWriter ¶
GetWriter returns the customized writer object, which implements the io.Writer interface. It returns nil if no writer previously set.
func (*Logger) Header ¶
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 ¶
Infof prints the logging content with [INFO] header, custom format and newline.
func (*Logger) Level ¶
Level is a chaining function, which sets logging level for the current logging content output.
func (*Logger) Line ¶
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 ¶
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) Panic ¶
func (l *Logger) Panic(v ...interface{})
Panic prints the logging content with [PANI] header and newline, then panics.
func (*Logger) Panicf ¶
Panicf prints the logging content with [PANI] header, custom format and newline, then panics.
func (*Logger) Path ¶
Path is a chaining function, which sets the directory path to <path> for current logging content output.
Note that the parameter <path> is a directory path, not a file path.
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 ¶
PrintStack prints the caller stack, the optional parameter <skip> specify the skipped stack offset from the end point.
func (*Logger) Printf ¶
Printf prints <v> with format <format> using fmt.Sprintf. The parameter <v> can be multiple variables.
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println is alias of Print. See Print.
func (*Logger) SetConfigWithMap ¶ added in v1.10.0
SetConfigWithMap set configurations with map for the logger.
func (*Logger) SetDebug ¶
SetDebug enables/disables the debug level for logger. The debug level is enabled in default.
func (*Logger) SetFile ¶
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) SetHeaderPrint ¶
SetHeaderPrint sets whether output header of the logging contents, which is true in default.
func (*Logger) SetLevelPrefix ¶ added in v1.11.5
SetLevelPrefix sets the prefix string for specified level.
func (*Logger) SetLevelPrefixes ¶ added in v1.11.5
SetLevelPrefixes sets the level to prefix string mapping for the logger.
func (*Logger) SetPrefix ¶
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) SetStackFilter ¶
SetStackFilter sets the stack filter from the end point.
func (*Logger) SetStackSkip ¶
SetStackSkip sets the stack offset from the end point.
func (*Logger) SetStdoutPrint ¶
SetStdoutPrint sets whether output the logging contents to stdout, which is true in default.
func (*Logger) SetWriter ¶
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 ¶
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 ¶
Stack is a chaining function, which sets stack options for the current logging content output .
func (*Logger) StackWithFilter ¶
StackWithFilter is a chaining function, which sets stack filter for the current logging content output .
func (*Logger) Stdout ¶
Stdout is a chaining function, which enables/disables stdout for the current logging content output. It's enabled in default.
func (*Logger) To ¶
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.