Repository navigation
Logging
Caleb Hiebert edited this page May 31, 2019
·
1 revision
Gobbl has some built in logging tools to make it easier to track requests
There are a number of built in logging levels
- TRACE - 50
- DEBUG - 40
- INFO - 30
- WARN - 20
- ERROR - 10
Logs will be printed to the console by default. They have the following format:
[<time since request start> | <source name> | <request id>] <level> <message>
The gobbl context contains convenience functions for logging:
func HGetStarted(c *gbl.Context) {
// Standard Variants
c.Trace("trace log message")
c.Debug("debug log message")
c.Info("info log message")
c.Warn("heed this warning")
c.Error("panic!")
// Formatting variants
c.Tracef("example trace %+v", data)
c.Debugf("example debug %+v", data)
c.Infof("example info %+v", data)
c.Warnf("example warning %+v", data)
c.Errorf("panic! %v", err)
}Logging at custom levels can be achieved with the Log function
func HGetStarted(c *gbl.Context) {
// func Log(level int, msg string, source string) {
c.Log(8, "message with custom log level", "HGetStarted")
}The logging system supports changing configuration based on environment variables
-
LOG_COLORS("true" or "false", default false) - controls whether or not the log messages will use color when printing to the console -
LOG_LEVEL(positive int, default 20) - messages logged at a level higher than LOG_LEVEL will be hidden