Documentation
¶
Overview ¶
Usage:
import "github.com/baidu/go-lib/log" // Two log files will be generated in ./log: // test.log, and test.wf.log(for log > warn) // The log will rotate, and there is support for backup count log.Init("test", "INFO", "./log", true, "midnight", 5) log.Logger.Warn("warn msg") log.Logger.Info("info msg") // it is required, to work around bug of log4go time.Sleep(100 * time.Millisecond)
Index ¶
- Variables
- func Create(progName string, levelStr string, logDir string, hasStdOut bool, when string, ...) (log4go.Logger, error)
- func Init(progName string, levelStr string, logDir string, hasStdOut bool, when string, ...) error
- func InitWithCompress(progName string, levelStr string, logDir string, hasStdOut bool, when string, ...) error
- func InitWithLogSvr(progName string, levelStr string, loggerName string, network string, ...) error
Constants ¶
This section is empty.
Variables ¶
View Source
var Logger log4go.Logger
Logger is global logger
Functions ¶
func Create ¶
func Create(progName string, levelStr string, logDir string, hasStdOut bool, when string, backupCount int) (log4go.Logger, error)
Create creates log lib
PARAMS:
- progName: program name. Name of log file will be progName.log
- levelStr: "DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"
- logDir: directory for log. It will be created if noexist
- hasStdOut: whether to have stdout output
- when: "M", minute "H", hour "D", day "MIDNIGHT", roll over at midnight
- backupCount: If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted.
func Init ¶
func Init(progName string, levelStr string, logDir string, hasStdOut bool, when string, backupCount int) error
Init initializes log lib
PARAMS:
- progName: program name. Name of log file will be progName.log
- levelStr: "DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"
- logDir: directory for log. It will be created if noexist
- hasStdOut: whether to have stdout output
- when: "M", minute "H", hour "D", day "MIDNIGHT", roll over at midnight
- backupCount: If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted.
func InitWithCompress ¶
func InitWithCompress(progName string, levelStr string, logDir string, hasStdOut bool, when string, backupCount int, enableCompress bool) error
Init initializes log lib
PARAMS:
- progName: program name. Name of log file will be progName.log
- levelStr: "DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"
- logDir: directory for log. It will be created if noexist
- hasStdOut: whether to have stdout output
- when: "M", minute "H", hour "D", day "MIDNIGHT", roll over at midnight
- backupCount: If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted.
- enableCompress: whether to compress the roll over log file
func InitWithLogSvr ¶
func InitWithLogSvr(progName string, levelStr string, loggerName string, network string, svrAddr string, svrAddrWf string, hasStdOut bool) error
InitWithLogSvr initializes log lib with remote log server
PARAMS:
- progName: program name.
- levelStr: "DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"
- loggerName: logger name
- network: using "udp" or "unixgram"
- svrAddr: remote unix sock address for all logger
- svrAddrWf: remote unix sock address for warn/fatal logger If svrAddrWf is empty string, no warn/fatal logger will be created.
- hasStdOut: whether to have stdout output
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.