Documentation ¶
Overview ¶
Package golog provides a simple alternative to standard log that defines a Logger interface allowing custom logger to be used across the application and its libraries.
To begin with, import the golog package and start using its exported functions like:
import "github.com/bnclabs/golog" ... log.Printf() log.Fatalf()
Default logger will be used in the above case. To configure default logger:
setts := map[string]interface{}{ "log.level": "info", "log.flags": "", "log.file": "", "log.timeformat": timeformat, "log.prefix": prefix, "log.colorignore": "", "log.colorfatal": "red", "log.colorerror": "hired", "log.colorwarn": "yellow", "log.colorinfo": "", "log.colorverbose": "", "log.colordebug": "", "log.colortrace": "", } log.SetLogger(nil, setts)
Default logger will be configured to "info" level. Refer Defaultsettings() for description on each settings parameter.
To configure a custom logger:
log.Setlogger(customlogger, nil)
Note that `customlogger` should implement the Logger interface.
Index ¶
- Variables
- func Consolef(format string, v ...interface{})
- func Debugf(format string, v ...interface{})
- func Defaultsettings() map[string]interface{}
- func Errorf(format string, v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Infof(format string, v ...interface{})
- func Tracef(format string, v ...interface{})
- func Verbosef(format string, v ...interface{})
- func Warnf(format string, v ...interface{})
- type LogLevel
- type Logger
Constants ¶
This section is empty.
Variables ¶
var DefaultLogLevel = "info"
DefaultLogLevel to use if log.level option is missing.
Functions ¶
func Consolef ¶
func Consolef(format string, v ...interface{})
Consolef similar to Printf, will log to os.Stdout.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf similar to Printf, will be logged only when log level is set as "debug" or above.
func Defaultsettings ¶
func Defaultsettings() map[string]interface{}
Defaultsettings used on default logger.
log.level: (default "info")
Level can be one of the following string, "ignore", "fatal", "error", "warn", "info", "verbose", "debug", "trace".
log.flags: (default "")
Flags can be comma seperated string values. These flags as exactly same as the golang's standard logger. "ldate" the date in the local time zone: 2009/01/23 "ltime" the time in the local time zone: 01:23:23 "lmicroseconds" microsecond resolution: 01:23:23.123123. "llongfile" full file name and line number: /a/b/c/d.go:23 "lshortfile" final file name element and line number: d.go:23. "lutc" if Ldate or Ltime is set, use UTC rather than the local time zone "lstdflags" initial values for the standard logger ldate,ltime
log.file: (default os.Stdout)
Optional log file name to log o/p. Except Consolef all functions will o/p to this file if supplied, else to standard output.
log.timeformat: "2006-01-02T15:04:05.999Z-07:00"
Log line timeformat.
log.prefix: [%v]
Prefix format for log-level.
log.colorfatal: "red"
Output color for fatal level.
log.colorerror: "hired"
Output color for error level.
log.colorwarn: "yellow"
Output color for warn level.
log.colorinfo: ""
Output color for info level.
log.colorverbose: "",
Output color for verbose level.
log.colordebug: "",
Output color for debug level.
log.colortrace: "",
Output color for trace level.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf similar to Printf, will be logged only when log level is set as "error" or above.
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf similar to Printf, will be logged only when log level is set as "fatal" or above.
func Infof ¶
func Infof(format string, v ...interface{})
Infof similar to Printf, will be logged only when log level is set as "info" or above.
func Tracef ¶
func Tracef(format string, v ...interface{})
Tracef similar to Printf, will be logged only when log level is set as "trace" or above.
Types ¶
type Logger ¶
type Logger interface { // SetLogLevel application's global log level, can be one of the // following: "ignore", "fatal", "error", "warn", "info", "verbose", // "debug", "trace" SetLogLevel(string) // SetLogFlags format of log prefix, following golang's log:Flag() // specification SetLogFlags(flags int) // SetTimeFormat to use as prefix for all log messages. SetTimeFormat(string) // SetLogprefix including the log level. SetLogprefix(interface{}) // SetLogcolor sets coloring attributes for specified log level, can be // a list of following attributes: "bold", "underline", "blinkslow", // "blinkrapid", "crossedout", // "red", "green", "yellow", "blue", "magenta", "cyan", "white" // "hired", "higreen", "hiyellow", "hiblue", "himagenta", "hicyan", // "hiwhite" SetLogcolor(level string, attrs []string) // Fatalf similar to Printf, will be logged only when log level is set as // "fatal" or above. Fatalf(format string, v ...interface{}) // Errorf similar to Printf, will be logged only when log level is set as // "error" or above. Errorf(format string, v ...interface{}) // Warnf similar to Printf, will be logged only when log level is set as // "warn" or above. Warnf(format string, v ...interface{}) // Infof similar to Printf, will be logged only when log level is set as // "info" or above. Infof(format string, v ...interface{}) // Verbosef similar to Printf, will be logged only when log level is set as // "verbose" or above. Verbosef(format string, v ...interface{}) // Debugf similar to Printf, will be logged only when log level is set as // "debug" or above. Debugf(format string, v ...interface{}) // Tracef similar to Printf, will be logged only when log level is set as // "trace" or above. Tracef(format string, v ...interface{}) // Printlf reserved for future extension. Printlf(loglevel LogLevel, format string, v ...interface{}) }
Logger interface for application logging, applications can supply a logger object implementing this interface, otherwise, defaultLogger{} will be used.