Add option to enable caller information in logger
Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
parent
cf87e8d07e
commit
2338ee4f25
3 changed files with 9 additions and 4 deletions
|
@ -42,6 +42,9 @@ type Configuration struct {
|
||||||
// Hooks allows users to configure the log hooks, to enabling the
|
// Hooks allows users to configure the log hooks, to enabling the
|
||||||
// sequent handling behavior, when defined levels of log message emit.
|
// sequent handling behavior, when defined levels of log message emit.
|
||||||
Hooks []LogHook `yaml:"hooks,omitempty"`
|
Hooks []LogHook `yaml:"hooks,omitempty"`
|
||||||
|
|
||||||
|
// ReportCaller allows user to configure the log to report the caller
|
||||||
|
ReportCaller bool `yaml:"reportcaller,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loglevel is the level at which registry operations are logged.
|
// Loglevel is the level at which registry operations are logged.
|
||||||
|
|
|
@ -23,10 +23,11 @@ var configStruct = Configuration{
|
||||||
AccessLog struct {
|
AccessLog struct {
|
||||||
Disabled bool `yaml:"disabled,omitempty"`
|
Disabled bool `yaml:"disabled,omitempty"`
|
||||||
} `yaml:"accesslog,omitempty"`
|
} `yaml:"accesslog,omitempty"`
|
||||||
Level Loglevel `yaml:"level,omitempty"`
|
Level Loglevel `yaml:"level,omitempty"`
|
||||||
Formatter string `yaml:"formatter,omitempty"`
|
Formatter string `yaml:"formatter,omitempty"`
|
||||||
Fields map[string]interface{} `yaml:"fields,omitempty"`
|
Fields map[string]interface{} `yaml:"fields,omitempty"`
|
||||||
Hooks []LogHook `yaml:"hooks,omitempty"`
|
Hooks []LogHook `yaml:"hooks,omitempty"`
|
||||||
|
ReportCaller bool `yaml:"reportcaller,omitempty"`
|
||||||
}{
|
}{
|
||||||
Level: "info",
|
Level: "info",
|
||||||
Fields: map[string]interface{}{"environment": "test"},
|
Fields: map[string]interface{}{"environment": "test"},
|
||||||
|
|
|
@ -345,6 +345,7 @@ func configureReporting(app *handlers.App) http.Handler {
|
||||||
// configuration.
|
// configuration.
|
||||||
func configureLogging(ctx context.Context, config *configuration.Configuration) (context.Context, error) {
|
func configureLogging(ctx context.Context, config *configuration.Configuration) (context.Context, error) {
|
||||||
logrus.SetLevel(logLevel(config.Log.Level))
|
logrus.SetLevel(logLevel(config.Log.Level))
|
||||||
|
logrus.SetReportCaller(config.Log.ReportCaller)
|
||||||
|
|
||||||
formatter := config.Log.Formatter
|
formatter := config.Log.Formatter
|
||||||
if formatter == "" {
|
if formatter == "" {
|
||||||
|
|
Loading…
Reference in a new issue