add IsDebug() shortcut method

This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-09-10 16:20:19 +03:00
parent ae67987f55
commit b17217444e
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
5 changed files with 22 additions and 2 deletions

View File

@ -609,7 +609,8 @@ New Package-level Variables:
New Context Methods: New Context Methods:
- `Context.IsRecovered()` reports whether the current request was recovered from the [recover middleware](https://github.com/kataras/iris/tree/master/middleware/recover). Also the `iris.IsErrPrivate` function and `iris.ErrPrivate` interface have been introduced. - `Context.IsDebug() bool` reports whether the application is running under debug/development mode. It is a shortcut of Application.Logger().Level >= golog.DebugLevel.
- `Context.IsRecovered() bool` reports whether the current request was recovered from the [recover middleware](https://github.com/kataras/iris/tree/master/middleware/recover). Also the `iris.IsErrPrivate` function and `iris.ErrPrivate` interface have been introduced.
- `Context.RecordBody()` same as the Application's `DisableBodyConsumptionOnUnmarshal` configuration field but registers per chain of handlers. It makes the request body readable more than once. - `Context.RecordBody()` same as the Application's `DisableBodyConsumptionOnUnmarshal` configuration field but registers per chain of handlers. It makes the request body readable more than once.
- `Context.IsRecordingBody() bool` reports whether the request body can be readen multiple times. - `Context.IsRecordingBody() bool` reports whether the request body can be readen multiple times.
- `Context.ReadHeaders(ptr interface{}) error` binds request headers to "ptr". [Example](https://github.com/kataras/iris/blob/master/_examples/request-body/read-headers/main.go). - `Context.ReadHeaders(ptr interface{}) error` binds request headers to "ptr". [Example](https://github.com/kataras/iris/blob/master/_examples/request-body/read-headers/main.go).

View File

@ -93,7 +93,7 @@ func getOrSetKey(ctx *context.Context) string {
} }
// Note: by-default the rules(ruleset pkg) // Note: by-default the rules(ruleset pkg)
// explictly ignores the cache handler // explicitly ignores the cache handler
// execution on authenticated requests // execution on authenticated requests
// and immediately runs the next handler: // and immediately runs the next handler:
// if !h.rule.Claim(ctx) ...see `Handler` method. // if !h.rule.Claim(ctx) ...see `Handler` method.

View File

@ -19,6 +19,11 @@ type Application interface {
// Logger returns the golog logger instance(pointer) that is being used inside the "app". // Logger returns the golog logger instance(pointer) that is being used inside the "app".
Logger() *golog.Logger Logger() *golog.Logger
// IsDebug reports whether the application is running
// under debug/development mode.
// It's just a shortcut of Logger().Level >= golog.DebugLevel.
// The same method existss as Context.IsDebug() too.
IsDebug() bool
// I18nReadOnly returns the i18n's read-only features. // I18nReadOnly returns the i18n's read-only features.
I18nReadOnly() I18nReadOnly I18nReadOnly() I18nReadOnly

View File

@ -5054,6 +5054,12 @@ func (ctx *Context) Application() Application {
return ctx.app return ctx.app
} }
// IsDebug reports whether the application runs with debug log level.
// It is a shortcut of Application.IsDebug().
func (ctx *Context) IsDebug() bool {
return ctx.app.IsDebug()
}
const errorContextKey = "iris.context.error" const errorContextKey = "iris.context.error"
// SetErr is just a helper that sets an error value // SetErr is just a helper that sets an error value

View File

@ -276,6 +276,14 @@ func (app *Application) Logger() *golog.Logger {
return app.logger return app.logger
} }
// IsDebug reports whether the application is running
// under debug/development mode.
// It's just a shortcut of Logger().Level >= golog.DebugLevel.
// The same method existss as Context.IsDebug() too.
func (app *Application) IsDebug() bool {
return app.logger.Level >= golog.DebugLevel
}
// I18nReadOnly returns the i18n's read-only features. // I18nReadOnly returns the i18n's read-only features.
// See `I18n` method for more. // See `I18n` method for more.
func (app *Application) I18nReadOnly() context.I18nReadOnly { func (app *Application) I18nReadOnly() context.I18nReadOnly {