Documentation ¶
Overview ¶
Package log connects to a local or remote syslog server with fallback to stderr output.
Index ¶
- Variables
- func Alert(a ...interface{})
- func Alertf(m string, a ...interface{})
- func Crit(a ...interface{})
- func Critf(m string, a ...interface{})
- func Debug(a ...interface{})
- func Debugf(m string, a ...interface{})
- func Dial(network, raddr, tag string, timeout time.Duration) error
- func Emerg(a ...interface{})
- func Emergf(m string, a ...interface{})
- func Error(err error)
- func Errorf(m string, a ...interface{})
- func Info(a ...interface{})
- func Infof(m string, a ...interface{})
- func Notice(a ...interface{})
- func Noticef(m string, a ...interface{})
- func Warning(a ...interface{})
- func Warningf(m string, a ...interface{})
- type Level
- type Logger
Constants ¶
This section is empty.
Variables ¶
var Close = func() error { if remoteLogger == nil { return nil } err := remoteLogger.Close() if err == nil { remoteLogger = nil } return err }
Close closes a connection to the syslog daemon. It is declared as a variable to allow an easy mocking.
var ( // ErrDialTimeout returned when a syslog dial connection takes too long to be // established. ErrDialTimeout = errors.New("dial timeout") )
var ( // LocalLogger is the fallback log used when the remote logger isn't // available. LocalLogger *log.Logger )
var NewLogger = func(id string) Logger {
return &logger{
identifier: "[" + id + "] ",
caller: 3,
}
}
NewLogger returns a internal instance of the Logger type tagging an identifier to every message logged. This identifier is useful to group many messages to one related transaction id.
Functions ¶
func Alertf ¶
func Alertf(m string, a ...interface{})
Alertf log an emergency message with arguments
func Debugf ¶
func Debugf(m string, a ...interface{})
Debugf log an emergency message with arguments
func Dial ¶
Dial establishes a connection to a log daemon by connecting to address raddr on the specified network. Each write to the returned writer sends a log message with the given facility, severity and tag. If network is empty, Dial will connect to the local syslog server. A connection timeout defines how long it will wait for the connection until a timeout error is raised.
func Emergf ¶
func Emergf(m string, a ...interface{})
Emergf log an emergency message with arguments
func Errorf ¶
func Errorf(m string, a ...interface{})
Errorf log an emergency message with arguments
Types ¶
type Level ¶
type Level int
Level defines the severity of an error. For example, if a custom error is created as bellow:
import "github.com/registrobr/gostk/log" type ErrDatabaseFailure struct { } func (e ErrDatabaseFailure) Error() string { return "database failure!" } func (e ErrDatabaseFailure) Level() log.Level { return log.LevelEmergency } When used with the Logger type will be written in the syslog in the corresponding log level.
const ( // LevelEmergency sets a high priority level of problem advising that system // is unusable. LevelEmergency Level = 0 // LevelAlert sets a high priority level of problem advising to correct // immediately. LevelAlert Level = 1 // LevelCritical sets a medium priority level of problem indicating a failure // in a primary system. LevelCritical Level = 2 // LevelError sets a medium priority level of problem indicating a non-urgent // failure. LevelError Level = 3 // LevelWarning sets a low priority level indicating that an error will occur // if action is not taken. LevelWarning Level = 4 // LevelNotice sets a low priority level indicating events that are unusual, // but not error conditions. LevelNotice Level = 5 // LevelInfo sets a very low priority level indicating normal operational // messages that require no action. LevelInfo Level = 6 // LevelDebug sets a very low priority level indicating information useful to // developers for debugging the application. LevelDebug Level = 7 )
Syslog level message, defined in RFC 5424, section 6.2.1
type Logger ¶
type Logger interface { Emerg(m ...interface{}) Emergf(m string, a ...interface{}) Alert(m ...interface{}) Alertf(m string, a ...interface{}) Crit(m ...interface{}) Critf(m string, a ...interface{}) Error(e error) Errorf(m string, a ...interface{}) Warning(m ...interface{}) Warningf(m string, a ...interface{}) Notice(m ...interface{}) Noticef(m string, a ...interface{}) Info(m ...interface{}) Infof(m string, a ...interface{}) Debug(m ...interface{}) Debugf(m string, a ...interface{}) // SetCaller defines the number of invocations to follow-up to retrieve the // actual caller of the log entry. For now is only used by the package easy // functions. SetCaller(n int) }
Logger allows logging messages in all different level types. As it is an interface it can be replaced by mocks for test purposes.