Documentation
¶
Overview ¶
Package logging implements a logging based on RFC5424 standards, simliar to syslog and PHP's PSR-3. This is beneficial for teams already using RFC5424 or PSR-3 as part of their logging practices for things such as PHP services. You can read more about RFC5424 at https://tools.ietf.org/html/rfc5424/ and PSR-3 at https://www.php-fig.org/psr/psr-3/.
Index ¶
- Constants
- type Level
- type Logger
- type NilLogger
- func (logger *NilLogger) Alert(msg string, context ...string) error
- func (logger *NilLogger) Critical(msg string, context ...string) error
- func (logger *NilLogger) Debug(msg string, context ...string) error
- func (logger *NilLogger) Emergency(msg string, context ...string) error
- func (logger *NilLogger) Error(msg string, context ...string) error
- func (logger *NilLogger) Informational(msg string, context ...string) error
- func (logger *NilLogger) Log(level Level, msg string, context ...string) error
- func (logger *NilLogger) Notice(msg string, context ...string) error
- func (logger *NilLogger) Warning(msg string, context ...string) error
- type StdoutLogger
- func (logger *StdoutLogger) Alert(msg string, context ...string) error
- func (logger *StdoutLogger) Critical(msg string, context ...string) error
- func (logger *StdoutLogger) Debug(msg string, context ...string) error
- func (logger *StdoutLogger) Emergency(msg string, context ...string) error
- func (logger *StdoutLogger) Error(msg string, context ...string) error
- func (logger *StdoutLogger) Informational(msg string, context ...string) error
- func (logger *StdoutLogger) Log(level Level, msg string, context ...string) error
- func (logger *StdoutLogger) Notice(msg string, context ...string) error
- func (logger *StdoutLogger) Warning(msg string, context ...string) error
Constants ¶
const ( // Emergency denotes the system is unusable. Emergency = iota // Alert denotes action must be taken immediately. Alert // Critical denotes critical conditions. Critical // Error denotes error conditions. Error // Warning denotes warning conditions. Warning // Notice denotes normal but significant condition. Notice // Informational denotes informational messages. Informational // Debug denotes debug-level messages. Debug )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface {
// Emergency denotes the system is unusable. Usage should accompany
// instances that cause a restart or program exit. A Logger itself should
// never panic or exit as part of a call to Emergency. The callee is
// responsible to manage program exit.
Emergency(msg string, context ...string) error
// Alert denotes action must be taken immediately.
Alert(msg string, context ...string) error
// Critical denotes critical conditions.
Critical(msg string, context ...string) error
// Error denotes error conditions.
Error(msg string, context ...string) error
// Warning denotes warning conditions.
Warning(msg string, context ...string) error
// Notice denotes normal but significant condition.
Notice(msg string, context ...string) error
// Informational denotes informational messages.
Informational(msg string, context ...string) error
// Debug denotes debug-level messages.
Debug(msg string, context ...string) error
// Log provides logging based on the passed log Level. When defining a
// custom Logger, it is recommended to implement a robust Log function and
// then call this function within other log functions such as Error.
Log(level Level, msg string, context ...string) error
}
Logger provides a standard set of logging functions. If you are looking to implement your own Logger, the StdoutLogger implementation is a good example.
func NewLogger ¶
NewLogger returns a singluar Logger instance that will distribute logs to all of the Loggers provided as arguments. If no arguments are provided, the StdoutLogger will be used as a default. Here is an example of creating a logger with multiple destinations.
logger := NewLogger(NewStdoutLogger(), NewPapertrailLogger(ptConfig))
type NilLogger ¶
type NilLogger struct{}
NilLogger doesn't do anything.
func NewNilLogger ¶
func NewNilLogger() *NilLogger
NewNilLogger creates a new instance of the NilLogger, which is useful for testing objects that require a Logger.
func (*NilLogger) Informational ¶
type StdoutLogger ¶
type StdoutLogger struct {
// contains filtered or unexported fields
}
StdoutLogger is the default Logger implementation. It will take messages and send them to os.stdout.
func NewStdoutLogger ¶
func NewStdoutLogger() *StdoutLogger
NewStdoutLogger creates a new instance of the StdoutLogger.
func (*StdoutLogger) Critical ¶
func (logger *StdoutLogger) Critical(msg string, context ...string) error
func (*StdoutLogger) Emergency ¶
func (logger *StdoutLogger) Emergency(msg string, context ...string) error
func (*StdoutLogger) Informational ¶
func (logger *StdoutLogger) Informational(msg string, context ...string) error
func (*StdoutLogger) Log ¶
func (logger *StdoutLogger) Log(level Level, msg string, context ...string) error