Documentation ¶
Overview ¶
Package log implements the log facilities for BCE. It supports log to stderr, stdout as well as log to file with rotating. It is safe to be called by multiple goroutines. By using the package level function to use the default logger:
log.SetLogHandler(log.STDOUT | log.FILE) // default is log to stdout log.SetLogDir("/tmp") // default is /tmp log.SetRotateType(log.ROTATE_DAY) // default is log.HOUR log.SetRotateSize(1 << 30) // default is 1GB log.SetLogLevel(log.INFO) // default is log.DEBUG log.Debug(1, 1.2, "a") log.Debugln(1, 1.2, "a") log.Debugf(1, 1.2, "a")
User can also create new logger without using the default logger:
customLogger := log.NewLogger() customLogger.SetLogHandler(log.FILE) customLogger.Debug(1, 1.2, "a")
The log format can also support custom setting by using the following interface:
log.SetLogFormat([]string{log.FMT_LEVEL, log.FMT_TIME, log.FMT_MSG})
Most of the cases just use the default format is enough:
[]string{FMT_LEVEL, FMT_LTIME, FMT_LOCATION, FMT_MSG}
Index ¶
- Constants
- Variables
- func Debug(msg ...interface{})
- func Debugf(format string, msg ...interface{})
- func Debugln(msg ...interface{})
- func Error(msg ...interface{})
- func Errorf(format string, msg ...interface{})
- func Errorln(msg ...interface{})
- func Fatal(msg ...interface{})
- func Fatalf(format string, msg ...interface{})
- func Fatalln(msg ...interface{})
- func Info(msg ...interface{})
- func Infof(format string, msg ...interface{})
- func Infoln(msg ...interface{})
- func NewLogger() *logger
- func Panic(msg ...interface{})
- func Panicf(format string, msg ...interface{})
- func Panicln(msg ...interface{})
- func SetLogDir(dir string) error
- func SetLogFormat(format []string)
- func SetLogHandler(h Handler)
- func SetLogLevel(l Level)
- func SetRotateSize(size int64) error
- func SetRotateType(r RotateStrategy)
- func Warn(msg ...interface{})
- func Warnf(format string, msg ...interface{})
- func Warnln(msg ...interface{})
- type Handler
- type Level
- type RotateStrategy
Constants ¶
const ( ROTATE_NONE RotateStrategy = iota ROTATE_DAY ROTATE_HOUR ROTATE_MINUTE ROTATE_SIZE DEFAULT_ROTATE_TYPE = ROTATE_HOUR DEFAULT_ROTATE_SIZE int64 = 1 << 30 DEFAULT_LOG_DIR = "/tmp" ROTATE_SIZE_FILE_PREFIX = "rotating" )
Constants for log rotating strategy when logging to file, default is by hour
const ( FMT_LEVEL = "level" FMT_LTIME = "ltime" // long time with microsecond FMT_TIME = "time" // just with second FMT_LOCATION = "location" // caller's location with file, line, function FMT_MSG = "msg" )
Constants of the log format components to support user custom specification
Variables ¶
var ( LOG_FMT_STR = map[string]string{ FMT_LEVEL: "[%s]", FMT_LTIME: "2006-01-02 15:04:05.000000", FMT_TIME: "2006-01-02 15:04:05", FMT_LOCATION: "%s:%d:%s:", FMT_MSG: "%s", } )
Functions ¶
func Debug ¶
func Debug(msg ...interface{})
Export package-level functions for logging messages by using the default logger. It supports 3 kinds of interface which is similar to the standard package "fmt": with suffix of "ln", "f" or nothing.
func SetLogDir ¶
SetLogDir - set the logging directory if logging to file.
PARAMS:
- dir: the logging directory
RETURNS:
- error: check the directory and try to make it, otherwise return the error.
func SetLogFormat ¶
func SetLogFormat(format []string)
SetLogFormat - set the log component of each record when logging it. The default log format is {FMT_LEVEL, FMT_LTIME, FMT_LOCATION, FMT_MSG}.
PARAMS:
- format: the format component array.
func SetLogHandler ¶
func SetLogHandler(h Handler)
SetLogHandler - set the handler of the logger
PARAMS:
- Handler: the handler defined in this package, now just support STDOUT, STDERR, FILE
func SetLogLevel ¶
func SetLogLevel(l Level)
SetLogLevel - set the level threshold of the logger, only level equal to or bigger than this value will be logged.
PARAMS:
- Level: the level defined in this package, now support 6 levels.
func SetRotateSize ¶
SetRotateSize - set the rotating size if logging to file and set the strategy of size.
PARAMS:
- size: the rotating size
RETURNS:
- error: check the value and return any error if error occurs.
func SetRotateType ¶
func SetRotateType(r RotateStrategy)
SetRotateType - set the rotating strategy if logging to file.
PARAMS:
- RotateStrategy: the rotate strategy defined in this package, now support 5 strategy.
Types ¶
type RotateStrategy ¶
type RotateStrategy uint8