From 2338ee4f256b3db91e549a3cf8ab2d6141538055 Mon Sep 17 00:00:00 2001 From: stonezdj Date: Fri, 2 Jun 2023 15:46:53 +0800 Subject: [PATCH] Add option to enable caller information in logger Signed-off-by: stonezdj --- configuration/configuration.go | 3 +++ configuration/configuration_test.go | 9 +++++---- registry/registry.go | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 1f773976b..e4a80144c 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -42,6 +42,9 @@ type Configuration struct { // Hooks allows users to configure the log hooks, to enabling the // sequent handling behavior, when defined levels of log message emit. 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. diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 38319f3d3..db56ca991 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -23,10 +23,11 @@ var configStruct = Configuration{ AccessLog struct { Disabled bool `yaml:"disabled,omitempty"` } `yaml:"accesslog,omitempty"` - Level Loglevel `yaml:"level,omitempty"` - Formatter string `yaml:"formatter,omitempty"` - Fields map[string]interface{} `yaml:"fields,omitempty"` - Hooks []LogHook `yaml:"hooks,omitempty"` + Level Loglevel `yaml:"level,omitempty"` + Formatter string `yaml:"formatter,omitempty"` + Fields map[string]interface{} `yaml:"fields,omitempty"` + Hooks []LogHook `yaml:"hooks,omitempty"` + ReportCaller bool `yaml:"reportcaller,omitempty"` }{ Level: "info", Fields: map[string]interface{}{"environment": "test"}, diff --git a/registry/registry.go b/registry/registry.go index 15eb94109..83e49debd 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -345,6 +345,7 @@ func configureReporting(app *handlers.App) http.Handler { // configuration. func configureLogging(ctx context.Context, config *configuration.Configuration) (context.Context, error) { logrus.SetLevel(logLevel(config.Log.Level)) + logrus.SetReportCaller(config.Log.ReportCaller) formatter := config.Log.Formatter if formatter == "" {