-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a configuration for setting audit logs level #3512
Conversation
@@ -13,7 +13,7 @@ has_children: false | |||
{% include toc.html %} | |||
|
|||
Configuring lakeFS is done using a yaml configuration file and/or environment variable. | |||
The configuration file location can be set with the '--config' flag. If not specified, the the first file found in the following order will be used: | |||
The configuration file location can be set with the '--config' flag. If not specified, the first file found in the following order will be used: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
pkg/httputil/logging.go
Outdated
"took": time.Since(startTime), | ||
"status_code": writer.StatusCode, | ||
"sent_bytes": writer.ResponseSize, | ||
}).Debug("HTTP call ended") | ||
} | ||
endLogMsg := "HTTP call ended" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
pkg/httputil/logging.go
Outdated
} | ||
endLogMsg := "HTTP call ended" | ||
|
||
switch strings.ToLower(middlewareLogLevel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/httputil/logging.go
Outdated
}) | ||
} | ||
} | ||
|
||
func LoggingMiddleware(requestIDHeaderName string, fields logging.Fields, traceRequestHeaders bool) func(next http.Handler) http.Handler { | ||
if logging.Level() == "trace" { | ||
loggingMiddlewareLevel := viper.GetString(config.LoggingAuditLogLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, we extract the configuration value from the config structure. The config structure also expose a method in this case it can also parse the string and return the logging level
pkg/httputil/logging.go
Outdated
@@ -63,6 +66,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f | |||
logging.MethodFieldKey: r.Method, | |||
logging.HostFieldKey: r.Host, | |||
logging.RequestIDFieldKey: reqID, | |||
logging.LoggerName: "MiddlewareLog", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Usually we have property called "service".
- How is this property is used? Because we didn't really create another logger and having a name can be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just my way to add a kind of "tag" for logs coming from the audit logger. Maybe I'll change it to something like log_source
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "audit": "api"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor suggestions - looks good.
@@ -13,6 +14,7 @@ type contextKey string | |||
|
|||
const ( | |||
RequestIDContextKey contextKey = "request_id" | |||
AuditLogEndMessage string = "HTTP call ended" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- No need the type - constant will get the type while using it.
- You can update the message to include
API call information
or something like that if it make more sense.
AuditLogEndMessage string = "HTTP call ended" | |
AuditLogEndMessage = "HTTP call ended" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/logging/dummy.go
Outdated
@@ -52,6 +52,10 @@ func (d DummyLogger) Panic(args ...interface{}) { | |||
|
|||
} | |||
|
|||
func (d DummyLogger) Log(level string, args ...interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it is time to have also level as part of the logging abstraction so we will not work with strings.
pkg/httputil/logging.go
Outdated
@@ -63,6 +66,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f | |||
logging.MethodFieldKey: r.Method, | |||
logging.HostFieldKey: r.Host, | |||
logging.RequestIDFieldKey: reqID, | |||
logging.LoggerName: "MiddlewareLog", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "audit": "api"
pkg/httputil/logging.go
Outdated
@@ -63,6 +65,7 @@ func DebugLoggingMiddleware(requestIDHeaderName string, fields logging.Fields) f | |||
logging.MethodFieldKey: r.Method, | |||
logging.HostFieldKey: r.Host, | |||
logging.RequestIDFieldKey: reqID, | |||
logging.LogSource: "MiddlewareLogger", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider "audit" with value "api"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Thank you!
No description provided.