Documentation
¶
Index ¶
- Variables
- func Debug(msg string, args ...interface{})
- func Error(msg string, args ...interface{})
- func Fatal(msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func NewContext(ctx context.Context, log *Log) context.Context
- func Panic(msg string, args ...interface{})
- func Warning(msg string, args ...interface{})
- type Entry
- type Field
- type Level
- type Log
- func (l *Log) Critical(msg string, args ...interface{})
- func (l *Log) Debug(msg string, args ...interface{})
- func (l *Log) Error(msg string, args ...interface{})
- func (l *Log) Info(msg string, args ...interface{})
- func (l *Log) Trace(msg string, args ...interface{})
- func (l *Log) Warning(msg string, args ...interface{})
- func (l *Log) WithFields(fields ...Field) *Log
- func (l *Log) Write(lvl Level, msg string, args ...interface{})
- type Option
- type Writer
- type WriterFunc
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLog is the *Log used in static functions and is returned from contexts when no *Log is present DefaultLog = &Log{writer: Discard} )
var Discard = WriterFunc(func(Entry) {})
Discard will drop the log entries into the abyss (or do nothing)
Functions ¶
func NewContext ¶
NewContext creates a child context of the supplied context embedding the *Log. This *Log can be retrieved with the FromContext
Types ¶
type Entry ¶
type Entry struct { Level Level Timestamp time.Time Message string Arguments []interface{} Fields []Field }
Entry represents a single log
type Level ¶
type Level uint8
Level for logging Levels are defaulted to that of syslog severity level https://en.wikipedia.org/wiki/Syslog
Interpretation of the Levels is up to the appliation that is using them, the comments provided are only recommendations
const ( // LevelEmergency - A panic condition. LevelEmergency Level = iota // LevelAlert - A condition that should be corrected immediately, such as a corrupted system database. LevelAlert // LevelCritical - Hard application/device/hardware failures LevelCritical // LevelError - non-recoverable application errors LevelError // LevelWarning - recoverable application errors LevelWarning // LevelNotice - Conditions that are not error conditions, but may require special handling LevelNotice // LevelInformational - Messages that contain information about the application operation LevelInformational // LevelDebug - Messages that contain information normally of use only when debugging a program LevelDebug // LevelTrace - Messages that are likely only using while developing applications // // This is not part of the syslog spec, and might not be supported by all logging.Writer implementations LevelTrace // LevelNone - Not inteded to have output LevelNone Level = 255 )
func (Level) Is ¶
Is will return if the provided Level is verbose enough from the current level. This is suitable for checking before outputing logs
i.e. entry.Level.Is(LevelDebug) => write it when Debug-Emergency Level
func (Level) MarshalSetting ¶
MarshalSetting provides the custom string output for the log level in config
func (*Level) UnmarshalSetting ¶
UnmarshalSetting provides the custom parsing of log levels in config
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log for ... writing logs
func FromContext ¶
FromContext will return the logger for the specified context or the default one
func (*Log) WithFields ¶
WithFields will create a child logger sharing the same output as the parent with the additional fields specified
type Option ¶
type Option func(*Log)
Option for logging
func WithFields ¶
WithFields options will append the specified fields to the Log
func WithWriter ¶
WithWriter option will set the underlying write for the logs
type Writer ¶
type Writer interface {
Write(e Entry)
}
Writer interface for putting log Entry somewhere, someway
type WriterFunc ¶
type WriterFunc func(e Entry)
WriterFunc implements the logging.Writer interface to cast functions to the Writer
func (WriterFunc) Write ¶
func (w WriterFunc) Write(e Entry)