mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-09 13:58:11 +00:00
fix: improve logging in routines
This commit is contained in:
@@ -252,7 +252,7 @@ func (app *BootstrapApp) Setup() error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.ctx.Done():
|
case <-app.ctx.Done():
|
||||||
app.log.App.Debug().Msg("Oh, seems like I got to shutdown, bye!")
|
app.log.App.Info().Msg("Oh, seems like I got to shutdown, bye!")
|
||||||
app.db.Close()
|
app.db.Close()
|
||||||
return nil
|
return nil
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
@@ -410,6 +410,8 @@ func (app *BootstrapApp) dbCleanupRoutine() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
app.log.App.Error().Err(err).Msg("Failed to delete expired sessions")
|
app.log.App.Error().Err(err).Msg("Failed to delete expired sessions")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.log.App.Debug().Msg("Database cleanup completed")
|
||||||
case <-app.ctx.Done():
|
case <-app.ctx.Done():
|
||||||
app.log.App.Debug().Msg("Stopping database cleanup routine")
|
app.log.App.Debug().Msg("Stopping database cleanup routine")
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
|||||||
@@ -2,21 +2,16 @@ package bootstrap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
|
||||||
|
|
||||||
"github.com/tinyauthapp/tinyauth/internal/controller"
|
"github.com/tinyauthapp/tinyauth/internal/controller"
|
||||||
"github.com/tinyauthapp/tinyauth/internal/middleware"
|
"github.com/tinyauthapp/tinyauth/internal/middleware"
|
||||||
"github.com/tinyauthapp/tinyauth/internal/model"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DEV_MODES = []string{"main", "test", "development"}
|
|
||||||
|
|
||||||
func (app *BootstrapApp) setupRouter() error {
|
func (app *BootstrapApp) setupRouter() error {
|
||||||
if !slices.Contains(DEV_MODES, model.Version) {
|
// we don't want gin debug mode
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
}
|
|
||||||
|
|
||||||
engine := gin.New()
|
engine := gin.New()
|
||||||
engine.Use(gin.Recovery())
|
engine.Use(gin.Recovery())
|
||||||
|
|||||||
@@ -724,12 +724,16 @@ func (auth *AuthService) EndOAuthSession(sessionId string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (auth *AuthService) CleanupOAuthSessionsRoutine() {
|
func (auth *AuthService) CleanupOAuthSessionsRoutine() {
|
||||||
|
auth.log.App.Debug().Msg("Starting OAuth session cleanup routine")
|
||||||
|
|
||||||
ticker := time.NewTicker(30 * time.Minute)
|
ticker := time.NewTicker(30 * time.Minute)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
auth.log.App.Debug().Msg("Running OAuth session cleanup")
|
||||||
|
|
||||||
auth.oauthMutex.Lock()
|
auth.oauthMutex.Lock()
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -741,7 +745,9 @@ func (auth *AuthService) CleanupOAuthSessionsRoutine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth.oauthMutex.Unlock()
|
auth.oauthMutex.Unlock()
|
||||||
|
auth.log.App.Debug().Msg("OAuth session cleanup completed")
|
||||||
case <-auth.context.Done():
|
case <-auth.context.Done():
|
||||||
|
auth.log.App.Debug().Msg("Stopping OAuth session cleanup routine")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ func (ldap *LdapService) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
ldap.log.App.Debug().Msg("Starting LDAP connection heartbeat routine")
|
||||||
|
|
||||||
ticker := time.NewTicker(5 * time.Minute)
|
ticker := time.NewTicker(5 * time.Minute)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ func NewOAuthBrokerService(
|
|||||||
configs map[string]model.OAuthServiceConfig,
|
configs map[string]model.OAuthServiceConfig,
|
||||||
) *OAuthBrokerService {
|
) *OAuthBrokerService {
|
||||||
return &OAuthBrokerService{
|
return &OAuthBrokerService{
|
||||||
|
log: log,
|
||||||
services: make(map[string]OAuthServiceImpl),
|
services: make(map[string]OAuthServiceImpl),
|
||||||
configs: configs,
|
configs: configs,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -756,14 +756,14 @@ func (service *OIDCService) DeleteOldSession(ctx context.Context, sub string) er
|
|||||||
|
|
||||||
// Cleanup routine - Resource heavy due to the linked tables
|
// Cleanup routine - Resource heavy due to the linked tables
|
||||||
func (service *OIDCService) cleanupRoutine() {
|
func (service *OIDCService) cleanupRoutine() {
|
||||||
|
service.log.App.Debug().Msg("Starting OIDC cleanup routine")
|
||||||
ticker := time.NewTicker(time.Duration(30) * time.Minute)
|
ticker := time.NewTicker(time.Duration(30) * time.Minute)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
service.log.App.Debug().Msg("Starting OIDC cleanup routine")
|
service.log.App.Debug().Msg("Performing OIDC cleanup routine")
|
||||||
|
|
||||||
currentTime := time.Now().Unix()
|
currentTime := time.Now().Unix()
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ func (l *Logger) Init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if base.GetLevel() == zerolog.TraceLevel || base.GetLevel() == zerolog.DebugLevel {
|
||||||
|
base = base.With().Caller().Logger()
|
||||||
|
}
|
||||||
|
|
||||||
l.base = base
|
l.base = base
|
||||||
l.audit = l.createLogger("audit", l.config.Streams.Audit)
|
l.audit = l.createLogger("audit", l.config.Streams.Audit)
|
||||||
l.HTTP = l.createLogger("http", l.config.Streams.HTTP)
|
l.HTTP = l.createLogger("http", l.config.Streams.HTTP)
|
||||||
@@ -113,9 +117,6 @@ func (l *Logger) createLogger(component string, cfg model.LogStreamConfig) zerol
|
|||||||
if cfg.Level != "" {
|
if cfg.Level != "" {
|
||||||
sub = sub.Level(l.parseLogLevel(cfg.Level))
|
sub = sub.Level(l.parseLogLevel(cfg.Level))
|
||||||
}
|
}
|
||||||
if sub.GetLevel() == zerolog.DebugLevel {
|
|
||||||
sub = sub.With().Caller().Logger()
|
|
||||||
}
|
|
||||||
return sub
|
return sub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ func TestLogger(t *testing.T) {
|
|||||||
l.AuditLoginFailure("test", "test", "test", "test")
|
l.AuditLoginFailure("test", "test", "test", "test")
|
||||||
|
|
||||||
assert.NotEmpty(t, buf.String())
|
assert.NotEmpty(t, buf.String())
|
||||||
assert.Equal(t, 119, buf.Len()) // it's the length of the test log entry
|
assert.Equal(t, 81, buf.Len()) // it's the length of the test log entry
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user