Documentation ¶
Index ¶
- Constants
- Variables
- func FileSyslog(level logging.Level, logdir string, module string) logging.LeveledBackend
- func Highlight(msg string, level logging.Level) string
- func SetupLog(level logging.Level, syslogaddr string, logdir string, module string)
- func SetupSyslog(level logging.Level, syslogaddr string, module string) logging.LeveledBackend
- type File
- type Stdlog
- type SyslogBackend
Constants ¶
const ModuleSystem = "System"
Variables ¶
var ( Error = log.Error ErrorIf = func(err error) { if err != nil { log.Error(err) } } Errorf = log.Errorf Info = log.Info Infof = log.Infof Warning = log.Warning Warningf = log.Warningf Fatal = log.Fatal Fatalf = log.Fatalf Debug = log.Debug Debugf = log.Debugf IsDebug = func() bool { return log.IsEnabledFor(logging.DEBUG) } )
Functions ¶
func FileSyslog ¶
func SetupSyslog ¶
Types ¶
type File ¶
File describes a file that gets rotated daily
func NewFile ¶
NewFile creates a new file that will be rotated daily (at midnight in specified location). pathFormat is file format accepted by time.Format that will be used to generate a name of the file. It should be unique in a given day e.g. 2006-01-02.txt. If you need more flexibility, use NewFileWithPathGenerator which accepts a function that generates a file path. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes) Warning: time.Format might format more than you expect e.g. time.Now().Format(`/logs/dir-2/2006-01-02.txt`) will change "-2" in "dir-2" to current day. For better control over path generation, use NewFileWithPathGenerator
func NewFileWithPathGenerator ¶
func NewFileWithPathGenerator(pathGenerator func(time.Time) string, onClose func(path string, didRotate bool)) (*File, error)
NewFileWithPathGenerator creates a new file that will be rotated daily (at midnight in timezone specified by in specified location). pathGenerator is a function that will return a path for a daily log file. It should be unique in a given day e.g. time.Format of "2006-01-02.txt" creates a string unique for the day. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes)
type SyslogBackend ¶
SyslogBackend is a simple logger to syslog backend. It automatically maps the internal log levels to appropriate syslog log levels.
func NewSyslogBackend ¶
func NewSyslogBackend(prefix string, syslogaddr string, priority syslog.Priority) (b *SyslogBackend, err error)
NewSyslogBackend connects to the syslog daemon using UNIX sockets with the given prefix. If prefix is not given, the prefix will be derived from the launched command.
func NewSyslogBackendPriority ¶
func NewSyslogBackendPriority(prefix string, priority syslog.Priority) (b *SyslogBackend, err error)
NewSyslogBackendPriority is the same as NewSyslogBackend, but with custom syslog priority, like syslog.LOG_LOCAL3|syslog.LOG_DEBUG etc.
func (*SyslogBackend) Log ¶
func (b *SyslogBackend) Log(level logging.Level, calldepth int, rec *logging.Record) error
Log implements the Backend interface.