mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 20:41:57 +00:00
Update to v3.0.0-beta.4 - Logger changes book, examples updated
This commit is contained in:
@@ -21,12 +21,6 @@ type (
|
||||
// using Config().Sessions...
|
||||
// and so on...
|
||||
Iris struct {
|
||||
// MaxRequestBodySize Maximum request body size.
|
||||
//
|
||||
// The server rejects requests with bodies exceeding this limit.
|
||||
//
|
||||
// By default request body size is -1, unlimited.
|
||||
MaxRequestBodySize int64
|
||||
|
||||
// DisablePathCorrection corrects and redirects the requested path to the registed path
|
||||
// for example, if /home/ path is requested but no handler for this Route found,
|
||||
@@ -50,15 +44,18 @@ type (
|
||||
// Default is false
|
||||
DisablePathEscape bool
|
||||
|
||||
// DisableLog turn it to true if you want to disable logger,
|
||||
// Iris prints/logs ONLY errors, so be careful when you enable it
|
||||
DisableLog bool
|
||||
|
||||
// DisableBanner outputs the iris banner at startup
|
||||
//
|
||||
// Default is false
|
||||
DisableBanner bool
|
||||
|
||||
// MaxRequestBodySize Maximum request body size.
|
||||
//
|
||||
// The server rejects requests with bodies exceeding this limit.
|
||||
//
|
||||
// By default request body size is -1, unlimited.
|
||||
MaxRequestBodySize int64
|
||||
|
||||
// Profile set to true to enable web pprof (debug profiling)
|
||||
// Default is false, enabling makes available these 7 routes:
|
||||
// /debug/pprof/cmdline
|
||||
@@ -74,6 +71,10 @@ type (
|
||||
// Default is /debug/pprof , which means yourhost.com/debug/pprof
|
||||
ProfilePath string
|
||||
|
||||
// Logger the configuration for the logger
|
||||
// Iris logs ONLY errors and the banner if enabled
|
||||
Logger Logger
|
||||
|
||||
// Sessions the config for sessions
|
||||
// contains 3(three) properties
|
||||
// Provider: (look /sessions/providers)
|
||||
@@ -86,6 +87,7 @@ type (
|
||||
|
||||
// Websocket contains the configs for Websocket's server integration
|
||||
Websocket Websocket
|
||||
|
||||
// Mail contains the config for the mail sender service
|
||||
Mail Mail
|
||||
}
|
||||
@@ -117,11 +119,10 @@ func Default() Iris {
|
||||
return Iris{
|
||||
DisablePathCorrection: false,
|
||||
DisablePathEscape: false,
|
||||
MaxRequestBodySize: -1,
|
||||
DisableLog: false,
|
||||
DisableBanner: false,
|
||||
Profile: false,
|
||||
MaxRequestBodySize: -1,
|
||||
ProfilePath: DefaultProfilePath,
|
||||
Logger: DefaultLogger(),
|
||||
Sessions: DefaultSessions(),
|
||||
Render: DefaultRender(),
|
||||
Websocket: DefaultWebsocket(),
|
||||
|
||||
@@ -1,43 +1,85 @@
|
||||
package config
|
||||
|
||||
import "github.com/imdario/mergo"
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
const DefaultLoggerPrefix = "[IRIS] "
|
||||
|
||||
var (
|
||||
// TimeFormat default time format for any kind of datetime parsing
|
||||
TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
|
||||
)
|
||||
|
||||
type (
|
||||
// Logger contains the configs for the Logger
|
||||
// Logger contains the full configuration options fields for the Logger
|
||||
Logger struct {
|
||||
Out io.Writer
|
||||
// Out the (file) writer which the messages/logs will printed to
|
||||
// Default is os.Stdout
|
||||
Out *os.File
|
||||
// Prefix the prefix for each message
|
||||
Prefix string
|
||||
Flag int
|
||||
// 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
|
||||
|
||||
// background colors single SGR Code
|
||||
|
||||
// ColorBgDefault the background color for the normal message bodies
|
||||
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
|
||||
|
||||
// banners are the force printed/written messages, doesn't care about Disabled field
|
||||
// ColorFgBanner the foreground color for the banner
|
||||
ColorFgBanner int
|
||||
}
|
||||
)
|
||||
|
||||
// DefaultLogger returns the default configs for the Logger
|
||||
func DefaultLogger() Logger {
|
||||
return Logger{Out: os.Stdout, Prefix: "", Flag: 0}
|
||||
}
|
||||
|
||||
// Merge merges the default with the given config and returns the result
|
||||
func (c Logger) Merge(cfg []Logger) (config Logger) {
|
||||
|
||||
if len(cfg) > 0 {
|
||||
config = cfg[0]
|
||||
mergo.Merge(&config, c)
|
||||
} else {
|
||||
_default := c
|
||||
config = _default
|
||||
return Logger{
|
||||
Out: os.Stdout,
|
||||
Prefix: DefaultLoggerPrefix,
|
||||
Disabled: false,
|
||||
// foreground colors
|
||||
ColorFgDefault: int(color.FgHiWhite),
|
||||
ColorFgInfo: int(color.FgCyan),
|
||||
ColorFgSuccess: int(color.FgHiGreen),
|
||||
ColorFgWarning: int(color.FgHiMagenta),
|
||||
ColorFgDanger: int(color.FgHiRed),
|
||||
// background colors
|
||||
ColorBgDefault: int(color.BgHiBlack),
|
||||
ColorBgInfo: int(color.BgHiBlack),
|
||||
ColorBgSuccess: int(color.BgHiBlack),
|
||||
ColorBgWarning: int(color.BgHiBlack),
|
||||
ColorBgDanger: int(color.BgHiWhite),
|
||||
// banner colors
|
||||
ColorFgBanner: int(color.FgHiBlue),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// MergeSingle merges the default with the given config and returns the result
|
||||
|
||||
Reference in New Issue
Block a user