1
0
mirror of https://github.com/drakkan/sftpgo.git synced 2025-11-29 22:08:10 +02:00

logger: add specific logs for failed attempts to initialize a connection

This should allow for better integration in tools like fail2ban.

Hopefully fix #59
This commit is contained in:
Nicola Murino
2019-11-11 15:20:00 +01:00
parent 191da1ecaf
commit 4ff34b3e53
5 changed files with 79 additions and 23 deletions

View File

@@ -56,17 +56,23 @@ func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry {
// Write logs a new entry at the end of the HTTP request
func (l *StructuredLoggerEntry) Write(status, bytes int, elapsed time.Duration) {
metrics.HTTPRequestServed(status)
l.Logger.Info().Fields(l.fields).Int(
"resp_status", status).Int(
"resp_size", bytes).Int64(
"elapsed_ms", elapsed.Nanoseconds()/1000000).Str(
"sender", "httpd").Msg(
"")
l.Logger.Info().
Timestamp().
Str("sender", "httpd").
Fields(l.fields).
Int("resp_status", status).
Int("resp_size", bytes).
Int64("elapsed_ms", elapsed.Nanoseconds()/1000000).
Msg("")
}
// Panic logs panics
func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte) {
l.Logger.Error().Fields(l.fields).Str(
"stack", string(stack)).Str(
"panic", fmt.Sprintf("%+v", v)).Msg("")
l.Logger.Error().
Timestamp().
Str("sender", "httpd").
Fields(l.fields).
Str("stack", string(stack)).
Str("panic", fmt.Sprintf("%+v", v)).
Msg("")
}