Allow to log each finished session to filesystem

By providing CORE_SESSIONS_SESSION_LOG_PATH_PATTERN (e.g. "/log/%Y-%m-%d.log") all
finished sessions will be logged to a file according to the provided strftime-pattern. The
actual value is calculated from when the session closed. CORE_SESSIONS_PERSIST must
be set. Default: not set.

Set CORE_SESSIONS_SESSION_LOG_BUFFER_SEC to the number of seconds the log should be
buffered in memory before persisted to disk. Default 15 seconds.
This commit is contained in:
Ingo Oppermann
2023-06-20 15:19:25 +02:00
parent 98e4dec13a
commit d3eed2a417
14 changed files with 786 additions and 187 deletions

View File

@@ -339,7 +339,10 @@ func (a *api) start() error {
if cfg.Sessions.Enable {
sessionConfig := session.Config{
Logger: a.log.logger.core.WithComponent("Session"),
PersistInterval: time.Duration(cfg.Sessions.PersistInterval) * time.Second,
LogPattern: cfg.Sessions.SessionLogPathPattern,
LogBufferDuration: time.Duration(cfg.Sessions.SessionLogBuffer) * time.Second,
Logger: a.log.logger.core.WithComponent("Session"),
}
if cfg.Sessions.Persist {
@@ -371,7 +374,6 @@ func (a *api) start() error {
MaxSessions: cfg.Sessions.MaxSessions,
InactiveTimeout: 5 * time.Second,
SessionTimeout: time.Duration(cfg.Sessions.SessionTimeout) * time.Second,
PersistInterval: time.Duration(cfg.Sessions.PersistInterval) * time.Second,
Limiter: iplimiter,
}
@@ -1823,6 +1825,7 @@ func (a *api) stop() {
// Stop the session tracker
if a.sessions != nil {
a.sessions.UnregisterAll()
a.sessions.Close()
a.sessions = nil
}