Documentation
¶
Index ¶
- Variables
- func AddDebugDomain(domain string, ttl time.Duration) error
- func DebugExpiration(domain string) *time.Time
- func Init(opt Options) error
- func RemoveDebugDomain(domain string) error
- func SyslogHook() (logrus.Hook, error)
- type Debugger
- type Entry
- func (e *Entry) AddHook(hook logrus.Hook)
- func (e *Entry) Debug(msg string)
- func (e *Entry) Debugf(format string, args ...interface{})
- func (e *Entry) Error(msg string)
- func (e *Entry) Errorf(format string, args ...interface{})
- func (e *Entry) Info(msg string)
- func (e *Entry) Infof(format string, args ...interface{})
- func (e *Entry) IsDebug() bool
- func (e *Entry) Log(level Level, msg string)
- func (e *Entry) Warn(msg string)
- func (e *Entry) Warnf(format string, args ...interface{})
- func (e *Entry) WithDomain(domain string) Logger
- func (e *Entry) WithField(key string, value interface{}) Logger
- func (e *Entry) WithFields(fields Fields) Logger
- func (e *Entry) WithNamespace(nspace string) *Entry
- func (e *Entry) WithTime(t time.Time) Logger
- func (e *Entry) Writer() *io.PipeWriter
- type Fields
- type Level
- type Logger
- type MemDebugger
- type Options
- type RedisDebugger
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidDomainFormat = errors.New("invalid domain format")
)
var (
ErrInvalidLevel = errors.New("not a valid logging Level")
)
Functions ¶
func AddDebugDomain ¶
AddDebugDomain adds the specified domain to the debug list.
func DebugExpiration ¶
DebugExpiration returns the expiration date for the debug mode for the instance logger of the given domain (or nil if the debug mode is not activated).
func Init ¶
Init initializes the logger module with the specified options.
It also setup the global logger for go-redis. Thoses are at Info level.
func RemoveDebugDomain ¶
RemoveDebugDomain removes the specified domain from the debug list.
func SyslogHook ¶
SyslogHook return a logrus.Hook sending all the logs to a local syslog server via a socket.
Types ¶
type Debugger ¶
type Debugger interface { AddDomain(domain string, ttl time.Duration) error RemoveDomain(domain string) error ExpiresAt(domain string) *time.Time }
Debugger manage the list of domains with the debug mode.
Once you call `AddDomain` all Debug logs containing the corresponding `domain` field (setup with `WithDomain`) will be printed even if the global logger is setup with a higher level (like 'info').
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is the struct on which we can call the Debug, Info, Warn, Error methods with the structured data accumulated.
func WithDomain ¶
WithDomain returns a logger with the specified domain field.
func WithNamespace ¶
WithNamespace returns a logger with the specified nspace field.
func (*Entry) WithDomain ¶
WithDomain add a domain field.
func (*Entry) WithFields ¶
WithFields adds a map of fields to the Entry.
func (*Entry) WithNamespace ¶
WithNamespace adds a namespace (nspace field).
func (*Entry) Writer ¶
func (e *Entry) Writer() *io.PipeWriter
type Level ¶
type Level uint8
Level type
const ( // ErrorLevel logs important errors when failure append. ErrorLevel Level // WarnLevel logs non critical entries that deserve some intention. WarnLevel // InfoLevel log general operational entries about what's going on inside // the application. InfoLevel // DebugLevel logs is only enabled when debugging is setup. It can be // very verbose logging and should be activated only on a limited period. DebugLevel )
These are the different logging levels.
func ParseLevel ¶
ParseLevel takes a string level and returns the log level constant.
func (Level) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Debug(msg string) Info(msg string) Warn(msg string) Error(msg string) // Generic field operations WithField(fn string, fv interface{}) Logger WithFields(fields Fields) Logger // Business specific field operations. WithTime(t time.Time) Logger WithDomain(s string) Logger Log(level Level, msg string) }
Logger allows to emits logs to the divers log systems.
type MemDebugger ¶
type MemDebugger struct {
// contains filtered or unexported fields
}
MemDebugger is a in-memory based Debugger implementation.
This implem is local only and is not suited for any multi-instance setup.
func NewMemDebugger ¶
func NewMemDebugger() *MemDebugger
NewMemDebugger instantiate a new MemDebugger.
func (*MemDebugger) AddDomain ¶
func (m *MemDebugger) AddDomain(domain string, ttl time.Duration) error
AddDomain adds the specified domain to the debug list.
func (*MemDebugger) ExpiresAt ¶
func (m *MemDebugger) ExpiresAt(domain string) *time.Time
ExpiresAt returns the expiration time for this domain.
If this domain is not in debug mode, it returns `nil`.
func (*MemDebugger) RemoveDomain ¶
func (m *MemDebugger) RemoveDomain(domain string) error
RemoveDomain removes the specified domain from the debug list.
type Options ¶
type Options struct { Hooks []logrus.Hook Output io.Writer Level string Redis redis.UniversalClient }
Options contains the configuration values of the logger system
type RedisDebugger ¶
type RedisDebugger struct {
// contains filtered or unexported fields
}
RedisDebugger is a redis based Debugger implementation.
It use redis to synchronize all the instances between them. This implementation is safe to use in a multi instance setup.
Technically speaking this is a wrapper around a MemDebugger using redis pub/sub and store for syncing the instances between them and restoring the domain list at startup.
func NewRedisDebugger ¶
func NewRedisDebugger(client redis.UniversalClient) (*RedisDebugger, error)
NewRedisDebugger instantiates a new RedisDebugger, bootstraps the service with the state saved in redis and starts the subscription to the change channel.
func (*RedisDebugger) AddDomain ¶
func (r *RedisDebugger) AddDomain(domain string, ttl time.Duration) error
AddDomain adds the specified domain to the debug list.
func (*RedisDebugger) Close ¶
func (r *RedisDebugger) Close() error
Close the redis client and the subscription channel.
func (*RedisDebugger) RemoveDomain ¶
func (r *RedisDebugger) RemoveDomain(domain string) error
RemoveDomain removes the specified domain from the debug list.