Documentation ¶
Overview ¶
Package logging enables setting custom logger implementation.
Basic Flow: 1) Initialize logger 2) Create new logger for specific module 3) Call log info
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) //Create new logger logger := NewLogger(modName) logger.Info("log test data") fmt.Println("log info is completed")
Output: log info is completed
Index ¶
- func Initialize(l api.LoggerProvider)
- func IsEnabledFor(module string, level Level) bool
- func SetLevel(module string, level Level)
- type Level
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Debugln(args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Errorln(args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Infoln(args ...interface{})
- func (l *Logger) Panic(args ...interface{})
- func (l *Logger) Panicf(format string, args ...interface{})
- func (l *Logger) Panicln(args ...interface{})
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Warnln(args ...interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
func Initialize(l api.LoggerProvider)
Initialize sets new logger which takes over logging operations. It is required to call this function before making any loggings.
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) fmt.Println("log is completed")
Output: log is completed
func IsEnabledFor ¶
IsEnabledFor - Check if given log level is enabled for given module
Parameters: module is module name level is logging level Returns: is logging enabled for this module and level
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) isEnabled := IsEnabledFor(modName, DEBUG) if !isEnabled { fmt.Println("log level debug is enabled") return } fmt.Println("log is completed")
Output: log is completed
Types ¶
type Level ¶
type Level int
Level defines all available log levels for log messages.
func GetLevel ¶
GetLevel - getting log level for given module
Parameters: module is module name Returns: logging level
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) SetLevel(modName, DEBUG) l := GetLevel(modName) if l != DEBUG { fmt.Println("log level is not debug") return } fmt.Println("log is completed")
Output: log is completed
func LogLevel ¶
LogLevel returns the log level from a string representation.
Parameters: level is logging level in string representation Returns: logging level
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) level, err := LogLevel("debug") if err != nil { fmt.Printf("failed LogLevel: %s\n", err) return } if level != DEBUG { fmt.Println("log level is not debug") return } fmt.Println("log is completed")
Output: log is completed
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger basic implementation of api.Logger interface
func NewLogger ¶
NewLogger creates and returns a Logger object based on the module name.
Example ¶
Initialize(testdata.GetSampleLoggingProvider(&buf)) //Create new logger NewLogger(modName) fmt.Println("log is completed")
Output: log is completed
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug calls Debug function of underlying logger
func (*Logger) Debugln ¶
func (l *Logger) Debugln(args ...interface{})
Debugln calls Debugln function of underlying logger
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error calls Error function of underlying logger
func (*Logger) Errorln ¶
func (l *Logger) Errorln(args ...interface{})
Errorln calls Errorln function of underlying logger
func (*Logger) Fatal ¶
func (l *Logger) Fatal(args ...interface{})
Fatal calls Fatal function of underlying logger
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(args ...interface{})
Fatalln calls Fatalln function of underlying logger
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info calls Info function of underlying logger
func (*Logger) Infoln ¶
func (l *Logger) Infoln(args ...interface{})
Infoln calls Infoln function of underlying logger
func (*Logger) Panic ¶
func (l *Logger) Panic(args ...interface{})
Panic calls Panic function of underlying logger
func (*Logger) Panicln ¶
func (l *Logger) Panicln(args ...interface{})
Panicln calls Panicln function of underlying logger
func (*Logger) Print ¶
func (l *Logger) Print(args ...interface{})
Print calls Print function of underlying logger
func (*Logger) Println ¶
func (l *Logger) Println(args ...interface{})
Println calls Println function of underlying logger
func (*Logger) Warn ¶
func (l *Logger) Warn(args ...interface{})
Warn calls Warn function of underlying logger