Documentation ¶
Overview ¶
Package logger contains filters and handles for the logging utilities in Revel. These facilities all currently use the logging library called log15 at https://github.com/inconshreveable/log15
Wrappers for the handlers are written here to provide a kind of isolation layer for Revel in case sometime in the future we would like to switch to another source to implement logging
Index ¶
- Constants
- Variables
- func GetLogger(name string, logger MultiLogger) (l *log.Logger)
- func NewCallStack() interface{}
- func NewCompositeMultiHandler() (*CompositeMultiHandler, LogHandler)
- func SetDefaultLog(fromLog MultiLogger)
- type CompositeMultiHandler
- func (h *CompositeMultiHandler) Disable(levels ...LogLevel)
- func (h *CompositeMultiHandler) Log(r *log15.Record) (err error)
- func (h *CompositeMultiHandler) SetHandler(handler LogHandler, replace bool, level LogLevel)
- func (h *CompositeMultiHandler) SetHandlers(handler LogHandler, options *LogOptions)
- func (h *CompositeMultiHandler) SetJson(writer io.Writer, options *LogOptions)
- func (h *CompositeMultiHandler) SetJsonFile(filePath string, options *LogOptions)
- func (h *CompositeMultiHandler) SetTerminal(writer io.Writer, options *LogOptions)
- func (h *CompositeMultiHandler) SetTerminalFile(filePath string, options *LogOptions)
- type ListLogHandler
- type LogFormat
- type LogHandler
- func CallerFileHandler(h LogHandler) LogHandler
- func CallerFuncHandler(h LogHandler) LogHandler
- func FilterHandler(fn func(r *log15.Record) bool, h LogHandler) LogHandler
- func LevelHandler(lvl LogLevel, h LogHandler) LogHandler
- func MatchAbHandler(key string, value interface{}, a, b LogHandler) LogHandler
- func MatchHandler(key string, value interface{}, h LogHandler) LogHandler
- func MatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler
- func MinLevelHandler(lvl LogLevel, h LogHandler) LogHandler
- func MultiHandler(hs ...LogHandler) LogHandler
- func NilHandler() LogHandler
- func NotLevelHandler(lvl LogLevel, h LogHandler) LogHandler
- func NotMatchHandler(key string, value interface{}, h LogHandler) LogHandler
- func NotMatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler
- func StreamHandler(wr io.Writer, fmtr LogFormat) LogHandler
- type LogLevel
- type LogOptions
- type LogStackHandler
- type MultiLogger
- type ParentLogHandler
- type RevelLogger
- func (rl *RevelLogger) Critf(msg string, param ...interface{})
- func (rl *RevelLogger) Debugf(msg string, param ...interface{})
- func (rl *RevelLogger) Errorf(msg string, param ...interface{})
- func (rl *RevelLogger) Fatal(msg string, ctx ...interface{})
- func (rl *RevelLogger) Fatalf(msg string, param ...interface{})
- func (rl *RevelLogger) Infof(msg string, param ...interface{})
- func (rl *RevelLogger) New(ctx ...interface{}) MultiLogger
- func (rl *RevelLogger) Panic(msg string, ctx ...interface{})
- func (rl *RevelLogger) Panicf(msg string, param ...interface{})
- func (rl *RevelLogger) SetHandler(h LogHandler)
- func (rl *RevelLogger) SetStackDepth(amount int) MultiLogger
- func (rl *RevelLogger) Warnf(msg string, param ...interface{})
Constants ¶
Variables ¶
var LogFunctionMap = map[string]func(*CompositeMultiHandler, *LogOptions){ "off": func(c *CompositeMultiHandler, logOptions *LogOptions) { if logOptions.HandlerWrap != nil { for _, l := range logOptions.Levels { c.SetHandler(logOptions.HandlerWrap.SetChild(NilHandler()), logOptions.ReplaceExistingHandler, l) } } }, "": func(*CompositeMultiHandler, *LogOptions) {}, "stdout": func(c *CompositeMultiHandler, logOptions *LogOptions) { if logOptions.Ctx != nil { logOptions.SetExtendedOptions( "noColor", !logOptions.Ctx.BoolDefault("log.colorize", true), "smallDate", logOptions.Ctx.BoolDefault("log.smallDate", true)) } c.SetTerminal(os.Stdout, logOptions) }, "stderr": func(c *CompositeMultiHandler, logOptions *LogOptions) { c.SetTerminal(os.Stderr, logOptions) }, }
The log function map can be added to, so that you can specify your own logging mechanism
A list of all the log levels
Functions ¶
func NewCallStack ¶
func NewCallStack() interface{}
For logging purposes the call stack can be used to record the stack trace of a bad error simply pass it as a context field in your log statement like `controller.Log.Critc("This should not occur","stack",revel.NewCallStack())`
func NewCompositeMultiHandler ¶
func NewCompositeMultiHandler() (*CompositeMultiHandler, LogHandler)
func SetDefaultLog ¶
func SetDefaultLog(fromLog MultiLogger)
Set the systems default logger Default logs will be captured and handled by revel at level info
Types ¶
type CompositeMultiHandler ¶
type CompositeMultiHandler struct { DebugHandler LogHandler InfoHandler LogHandler WarnHandler LogHandler ErrorHandler LogHandler CriticalHandler LogHandler }
func InitializeFromConfig ¶
func InitializeFromConfig(basePath string, config *config.Context) (c *CompositeMultiHandler)
Get all handlers based on the Config (if available)
func (*CompositeMultiHandler) Disable ¶
func (h *CompositeMultiHandler) Disable(levels ...LogLevel)
func (*CompositeMultiHandler) Log ¶
func (h *CompositeMultiHandler) Log(r *log15.Record) (err error)
func (*CompositeMultiHandler) SetHandler ¶
func (h *CompositeMultiHandler) SetHandler(handler LogHandler, replace bool, level LogLevel)
func (*CompositeMultiHandler) SetHandlers ¶
func (h *CompositeMultiHandler) SetHandlers(handler LogHandler, options *LogOptions)
func (*CompositeMultiHandler) SetJson ¶
func (h *CompositeMultiHandler) SetJson(writer io.Writer, options *LogOptions)
func (*CompositeMultiHandler) SetJsonFile ¶
func (h *CompositeMultiHandler) SetJsonFile(filePath string, options *LogOptions)
Use built in rolling function
func (*CompositeMultiHandler) SetTerminal ¶
func (h *CompositeMultiHandler) SetTerminal(writer io.Writer, options *LogOptions)
func (*CompositeMultiHandler) SetTerminalFile ¶
func (h *CompositeMultiHandler) SetTerminalFile(filePath string, options *LogOptions)
Use built in rolling function
type ListLogHandler ¶
type ListLogHandler struct {
// contains filtered or unexported fields
}
func NewListLogHandler ¶
func NewListLogHandler(h1, h2 LogHandler) *ListLogHandler
func (*ListLogHandler) Add ¶
func (ll *ListLogHandler) Add(h LogHandler)
func (*ListLogHandler) Del ¶
func (ll *ListLogHandler) Del(h LogHandler)
type LogFormat ¶
The LogHandler defines the interface to handle the log records
func TerminalFormatHandler ¶
Outputs to the terminal in a format like below INFO 09:11:32 server-engine.go:169: Request Stats
type LogHandler ¶
The LogHandler defines the interface to handle the log records
func CallerFileHandler ¶
func CallerFileHandler(h LogHandler) LogHandler
Adds in a context called `caller` to the record (contains file name and line number like `foo.go:12`) Uses the `log15.CallerFileHandler` to perform this task
func CallerFuncHandler ¶
func CallerFuncHandler(h LogHandler) LogHandler
Adds in a context called `caller` to the record (contains file name and line number like `foo.go:12`) Uses the `log15.CallerFuncHandler` to perform this task
func FilterHandler ¶
func FilterHandler(fn func(r *log15.Record) bool, h LogHandler) LogHandler
Filter handler, this is the only Uses the `log15.FilterHandler` to perform this task
func LevelHandler ¶
func LevelHandler(lvl LogLevel, h LogHandler) LogHandler
Filters out records which do not match the level Uses the `log15.FilterHandler` to perform this task
func MatchAbHandler ¶
func MatchAbHandler(key string, value interface{}, a, b LogHandler) LogHandler
If match then A handler is called otherwise B handler is called
func MatchHandler ¶
func MatchHandler(key string, value interface{}, h LogHandler) LogHandler
Filters out records which match the key value pair Uses the `log15.MatchFilterHandler` to perform this task
func MatchMapHandler ¶
func MatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler
Match all values in map to log
func MinLevelHandler ¶
func MinLevelHandler(lvl LogLevel, h LogHandler) LogHandler
Filters out records which do not match the level Uses the `log15.FilterHandler` to perform this task
func MultiHandler ¶
func MultiHandler(hs ...LogHandler) LogHandler
func NilHandler ¶
func NilHandler() LogHandler
The nil handler is used if logging for a specific request needs to be turned off
func NotLevelHandler ¶
func NotLevelHandler(lvl LogLevel, h LogHandler) LogHandler
Filters out records which match the level Uses the `log15.FilterHandler` to perform this task
func NotMatchHandler ¶
func NotMatchHandler(key string, value interface{}, h LogHandler) LogHandler
Filters out records which do not match the key value pair Uses the `log15.FilterHandler` to perform this task
func NotMatchMapHandler ¶
func NotMatchMapHandler(matchMap map[string]interface{}, a LogHandler) LogHandler
Match !(Match all values in map to log) The inverse of MatchMapHandler
func StreamHandler ¶
func StreamHandler(wr io.Writer, fmtr LogFormat) LogHandler
Outputs the records to the passed in stream Uses the `log15.StreamHandler` to perform this task
type LogOptions ¶
type LogOptions struct { Ctx *config.Context ReplaceExistingHandler bool HandlerWrap ParentLogHandler Levels []LogLevel ExtendedOptions map[string]interface{} }
Used for the callback to LogFunctionMap
func NewLogOptions ¶
func NewLogOptions(cfg *config.Context, replaceHandler bool, phandler ParentLogHandler, lvl ...LogLevel) (logOptions *LogOptions)
Create a new log options
func (*LogOptions) GetBoolDefault ¶
func (l *LogOptions) GetBoolDefault(option string, value bool) bool
func (*LogOptions) GetIntDefault ¶
func (l *LogOptions) GetIntDefault(option string, value int) int
func (*LogOptions) GetStringDefault ¶
func (l *LogOptions) GetStringDefault(option, value string) string
func (*LogOptions) SetExtendedOptions ¶
func (l *LogOptions) SetExtendedOptions(options ...interface{})
Assumes options will be an even number and have a string, value syntax
type LogStackHandler ¶
type LogStackHandler interface { LogHandler GetStack() int }
The LogHandler defines the interface to handle the log records
type MultiLogger ¶
type MultiLogger interface { //log15.Logger //// New returns a new Logger that has this logger's context plus the given context New(ctx ...interface{}) MultiLogger // //// SetHandler updates the logger to write records to the specified handler. SetHandler(h LogHandler) SetStackDepth(int) MultiLogger // //// Log a message at the given level with context key/value pairs Debug(msg string, ctx ...interface{}) Debugf(msg string, params ...interface{}) Info(msg string, ctx ...interface{}) Infof(msg string, params ...interface{}) Warn(msg string, ctx ...interface{}) Warnf(msg string, params ...interface{}) Error(msg string, ctx ...interface{}) Errorf(msg string, params ...interface{}) Crit(msg string, ctx ...interface{}) Critf(msg string, params ...interface{}) //// Logs a message as an Crit and exits Fatal(msg string, ctx ...interface{}) Fatalf(msg string, params ...interface{}) //// Logs a message as an Crit and panics Panic(msg string, ctx ...interface{}) Panicf(msg string, params ...interface{}) }
The Multilogger reduces the number of exposed defined logging variables, and allows the output to be easily refined
type ParentLogHandler ¶
type ParentLogHandler interface {
SetChild(handler LogHandler) LogHandler
}
The LogHandler defines the interface to handle the log records
func NewParentLogHandler ¶
func NewParentLogHandler(callBack func(child LogHandler) LogHandler) ParentLogHandler
type RevelLogger ¶
The LogHandler defines the interface to handle the log records
func (*RevelLogger) Critf ¶
func (rl *RevelLogger) Critf(msg string, param ...interface{})
func (*RevelLogger) Debugf ¶
func (rl *RevelLogger) Debugf(msg string, param ...interface{})
Formatted debug call
func (*RevelLogger) Errorf ¶
func (rl *RevelLogger) Errorf(msg string, param ...interface{})
func (*RevelLogger) Fatal ¶
func (rl *RevelLogger) Fatal(msg string, ctx ...interface{})
func (*RevelLogger) Fatalf ¶
func (rl *RevelLogger) Fatalf(msg string, param ...interface{})
func (*RevelLogger) Infof ¶
func (rl *RevelLogger) Infof(msg string, param ...interface{})
Formatted info call
func (*RevelLogger) New ¶
func (rl *RevelLogger) New(ctx ...interface{}) MultiLogger
Override log15 method
func (*RevelLogger) Panic ¶
func (rl *RevelLogger) Panic(msg string, ctx ...interface{})
func (*RevelLogger) Panicf ¶
func (rl *RevelLogger) Panicf(msg string, param ...interface{})
func (*RevelLogger) SetHandler ¶
func (rl *RevelLogger) SetHandler(h LogHandler)
Set the handler in the Logger
func (*RevelLogger) SetStackDepth ¶
func (rl *RevelLogger) SetStackDepth(amount int) MultiLogger
Set the stack level to check for the caller
func (*RevelLogger) Warnf ¶
func (rl *RevelLogger) Warnf(msg string, param ...interface{})