Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( DEBUG = iota INFO ERROR )
Variables ¶
This section is empty.
Functions ¶
func InitFileLogger ¶
InitFileLogger initializes the global logger with a file writer to filePath and set at level. It returns a function that clears the global logger. If the global logger is already initialized InitFileLogger panics.
Example ¶
Init a logger to file "/tmp/ubiquity.log" at DEBUG level
package main
import (
"github.com/midoblgsm/ubiquity/utils/logs"
)
func main() {
defer logs.InitFileLogger(logs.DEBUG, "/tmp/ubiquity.log")()
}
Output:
func InitStdoutLogger ¶
func InitStdoutLogger(level Level) func()
InitStdoutLogger initializes the global logger with stdout and set at level. It returns a function that clears the global logger. If the global logger is already initialized InitStdoutLogger panics.
Example ¶
Init a logger to stdout at DEBUG level
package main
import (
"github.com/midoblgsm/ubiquity/utils/logs"
)
func main() {
defer logs.InitStdoutLogger(logs.DEBUG)()
}
Output:
Types ¶
type Args ¶
type Args []nameValue
Args provides a way to safely pass additional params in a name=value format to the formatted log string.
type Level ¶
type Level int
func GetLogLevelFromString ¶ added in v0.4.0
GetLogLevelFromString translates string log level to Level type It returns the level for one of: "debug" / "info" / "error" If there is no match, default is INFO
type Logger ¶
type Logger interface {
// Debug writes the string and args at DEBUG level
Debug(str string, args ...Args)
// Info writes the string and args at INFO level
Info(str string, args ...Args)
// Error writes the string and args at ERROR level
Error(str string, args ...Args)
// ErrorRet writes the string and args at ERROR level, adding error=err to the args.
// It returns err, so its convenient to log the error and return it
ErrorRet(err error, str string, args ...Args) error
// Trace is used to write log message at upon entering and exiting the function.
// Unlike other Logger methods, it does not get a string for message.
// Instead, it writes only ENTER and EXIT
// It writes the ENTER message when called, and returns a function that writes the EXIT message,
// so it can be used with defer in 1 line
Trace(level Level, args ...Args) func()
}
Logger is the interface that wraps the basic log methods