Lint fixes

This commit is contained in:
Paul Tötterman
2020-10-19 13:40:52 +03:00
parent 3cec19ee62
commit 3d924a016b
65 changed files with 884 additions and 1083 deletions

View File

@@ -2,14 +2,15 @@ package logger
import (
"fmt"
"github.com/revel/config"
"time"
"github.com/revel/config"
)
// The LogHandler defines the interface to handle the log records
// The LogHandler defines the interface to handle the log records.
type (
// The Multilogger reduces the number of exposed defined logging variables,
// and allows the output to be easily refined
// and allows the output to be easily refined.
MultiLogger interface {
// New returns a new Logger that has this logger's context plus the given context
New(ctx ...interface{}) MultiLogger
@@ -63,32 +64,32 @@ type (
Panicf(msg string, params ...interface{})
}
// The log handler interface
// The log handler interface.
LogHandler interface {
Log(*Record) error
//log15.Handler
// log15.Handler
}
// The log stack handler interface
// The log stack handler interface.
LogStackHandler interface {
LogHandler
GetStack() int
}
// The log handler interface which has child logs
// The log handler interface which has child logs.
ParentLogHandler interface {
SetChild(handler LogHandler) LogHandler
}
// The log format interface
// The log format interface.
LogFormat interface {
Format(r *Record) []byte
}
// The log level type
// The log level type.
LogLevel int
// Used for the callback to LogFunctionMap
// Used for the callback to LogFunctionMap.
LogOptions struct {
Ctx *config.Context
ReplaceExistingHandler bool
@@ -97,22 +98,22 @@ type (
ExtendedOptions map[string]interface{}
}
// The log record
// The log record.
Record struct {
Message string // The message
Time time.Time // The time
Level LogLevel //The level
Level LogLevel // The level
Call CallStack // The call stack if built
Context ContextMap // The context
}
// The lazy structure to implement a function to be invoked only if needed
// The lazy structure to implement a function to be invoked only if needed.
Lazy struct {
Fn interface{} // the function
}
// Currently the only requirement for the callstack is to support the Formatter method
// which stack.Call does so we use that
// which stack.Call does so we use that.
CallStack interface {
fmt.Formatter // Requirement
}
@@ -129,6 +130,7 @@ type formatFunc func(*Record) []byte
func (f formatFunc) Format(r *Record) []byte {
return f(r)
}
func NewRecord(message string, level LogLevel) *Record {
return &Record{Message: message, Context: ContextMap{}, Level: level}
}
@@ -141,28 +143,28 @@ const (
LvlDebug // Debug
)
// A list of all the log levels
// LvlAllList is a list of all the log levels.
var LvlAllList = []LogLevel{LvlDebug, LvlInfo, LvlWarn, LvlError, LvlCrit}
// Implements the ParentLogHandler
// Implements the ParentLogHandler.
type parentLogHandler struct {
setChild func(handler LogHandler) LogHandler
}
// Create a new parent log handler
// Create a new parent log handler.
func NewParentLogHandler(callBack func(child LogHandler) LogHandler) ParentLogHandler {
return &parentLogHandler{callBack}
}
// Sets the child of the log handler
// Sets the child of the log handler.
func (p *parentLogHandler) SetChild(child LogHandler) LogHandler {
return p.setChild(child)
}
// Create a new log options
// Create a new log options.
func NewLogOptions(cfg *config.Context, replaceHandler bool, phandler ParentLogHandler, lvl ...LogLevel) (logOptions *LogOptions) {
logOptions = &LogOptions{
Ctx: cfg,
Ctx: cfg,
ReplaceExistingHandler: replaceHandler,
HandlerWrap: phandler,
Levels: lvl,
@@ -171,14 +173,14 @@ func NewLogOptions(cfg *config.Context, replaceHandler bool, phandler ParentLogH
return
}
// Assumes options will be an even number and have a string, value syntax
// Assumes options will be an even number and have a string, value syntax.
func (l *LogOptions) SetExtendedOptions(options ...interface{}) {
for x := 0; x < len(options); x += 2 {
l.ExtendedOptions[options[x].(string)] = options[x+1]
}
}
// Gets a string option with default
// Gets a string option with default.
func (l *LogOptions) GetStringDefault(option, value string) string {
if v, found := l.ExtendedOptions[option]; found {
return v.(string)
@@ -186,7 +188,7 @@ func (l *LogOptions) GetStringDefault(option, value string) string {
return value
}
// Gets an int option with default
// Gets an int option with default.
func (l *LogOptions) GetIntDefault(option string, value int) int {
if v, found := l.ExtendedOptions[option]; found {
return v.(int)
@@ -194,7 +196,7 @@ func (l *LogOptions) GetIntDefault(option string, value int) int {
return value
}
// Gets a boolean option with default
// Gets a boolean option with default.
func (l *LogOptions) GetBoolDefault(option string, value bool) bool {
if v, found := l.ExtendedOptions[option]; found {
return v.(bool)