iris/config/logger.go

102 lines
2.7 KiB
Go
Raw Normal View History

2016-05-30 16:08:09 +02:00
package config
import (
"github.com/fatih/color"
"github.com/imdario/mergo"
)
2016-05-30 16:08:09 +02:00
import (
"os"
)
2016-06-18 00:11:03 +02:00
// DefaultLoggerPrefix is the prefix (expect the [IRIS]), is empty for now
2016-06-06 20:46:28 +02:00
const DefaultLoggerPrefix = ""
2016-05-30 16:08:09 +02:00
var (
// TimeFormat default time format for any kind of datetime parsing
TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
)
type (
// Logger contains the full configuration options fields for the Logger
2016-05-30 16:08:09 +02:00
Logger struct {
// Out the (file) writer which the messages/logs will printed to
// Default is os.Stdout
Out *os.File
// Prefix the prefix for each message
2016-06-06 20:46:28 +02:00
// Default is ""
2016-05-30 16:08:09 +02:00
Prefix string
// Disabled default is false
Disabled bool
// foreground colors single SGR Code
// ColorFgDefault the foreground color for the normal message bodies
ColorFgDefault int
// ColorFgInfo the foreground color for info messages
ColorFgInfo int
// ColorFgSuccess the foreground color for success messages
ColorFgSuccess int
// ColorFgWarning the foreground color for warning messages
ColorFgWarning int
// ColorFgDanger the foreground color for error messages
ColorFgDanger int
2016-06-06 20:46:28 +02:00
// OtherFgColor the foreground color for the rest of the message types
ColorFgOther int
// background colors single SGR Code
2016-06-06 20:46:28 +02:00
// ColorBgDefault the background color for the normal messages
ColorBgDefault int
// ColorBgInfo the background color for info messages
ColorBgInfo int
// ColorBgSuccess the background color for success messages
ColorBgSuccess int
// ColorBgWarning the background color for warning messages
ColorBgWarning int
// ColorBgDanger the background color for error messages
ColorBgDanger int
2016-06-06 20:46:28 +02:00
// OtherFgColor the background color for the rest of the message types
ColorBgOther int
// banners are the force printed/written messages, doesn't care about Disabled field
2016-06-06 20:46:28 +02:00
// ColorFgBanner the foreground color for the banner
ColorFgBanner int
2016-05-30 16:08:09 +02:00
}
)
2016-06-03 04:11:50 +02:00
// DefaultLogger returns the default configs for the Logger
2016-05-30 16:08:09 +02:00
func DefaultLogger() Logger {
return Logger{
Out: os.Stdout,
2016-06-06 20:46:28 +02:00
Prefix: "",
Disabled: false,
// foreground colors
ColorFgDefault: int(color.FgHiWhite),
2016-06-06 20:46:28 +02:00
ColorFgInfo: int(color.FgHiCyan),
ColorFgSuccess: int(color.FgHiGreen),
ColorFgWarning: int(color.FgHiMagenta),
ColorFgDanger: int(color.FgHiRed),
2016-06-06 20:46:28 +02:00
ColorFgOther: int(color.FgHiYellow),
// background colors
ColorBgDefault: 0,
ColorBgInfo: 0,
ColorBgSuccess: 0,
ColorBgWarning: 0,
ColorBgDanger: 0,
ColorBgOther: 0,
2016-06-06 20:46:28 +02:00
// banner color
ColorFgBanner: int(color.FgHiBlue),
2016-05-30 16:08:09 +02:00
}
}
2016-06-01 14:29:38 +02:00
// MergeSingle merges the default with the given config and returns the result
2016-05-30 16:08:09 +02:00
func (c Logger) MergeSingle(cfg Logger) (config Logger) {
config = cfg
mergo.Merge(&config, c)
return
}