mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-01-16 04:12:29 +00:00
* Refactor logging to use centralized logger utility - Removed direct usage of zerolog in multiple files and replaced it with a centralized logging utility in the `utils` package. - Introduced `Loggers` struct to manage different loggers (Audit, HTTP, App) with configurable levels and outputs. - Updated all relevant files to utilize the new logging structure, ensuring consistent logging practices across the application. - Enhanced error handling and logging messages for better traceability and debugging. * refactor: update logging implementation to use new logger structure * Refactor logging to use tlog package - Replaced instances of utils logging with tlog in various controllers, services, and middleware. - Introduced audit logging for login success, login failure, and logout events. - Created tlog package with structured logging capabilities using zerolog. - Added tests for the new tlog logger functionality. * refactor: update logging configuration in environment files * fix: adding coderabbit suggestions * fix: ensure correct audit caller * fix: include reason in audit login failure logs
40 lines
927 B
Go
40 lines
927 B
Go
package tlog
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
// functions here use CallerSkipFrame to ensure correct caller info is logged
|
|
|
|
func AuditLoginSuccess(c *gin.Context, username, provider string) {
|
|
Audit.Info().
|
|
CallerSkipFrame(1).
|
|
Str("event", "login").
|
|
Str("result", "success").
|
|
Str("username", username).
|
|
Str("provider", provider).
|
|
Str("ip", c.ClientIP()).
|
|
Send()
|
|
}
|
|
|
|
func AuditLoginFailure(c *gin.Context, username, provider string, reason string) {
|
|
Audit.Warn().
|
|
CallerSkipFrame(1).
|
|
Str("event", "login").
|
|
Str("result", "failure").
|
|
Str("username", username).
|
|
Str("provider", provider).
|
|
Str("ip", c.ClientIP()).
|
|
Str("reason", reason).
|
|
Send()
|
|
}
|
|
|
|
func AuditLogout(c *gin.Context, username, provider string) {
|
|
Audit.Info().
|
|
CallerSkipFrame(1).
|
|
Str("event", "logout").
|
|
Str("result", "success").
|
|
Str("username", username).
|
|
Str("provider", provider).
|
|
Str("ip", c.ClientIP()).
|
|
Send()
|
|
}
|