log

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Audit

func Audit(entry AuditEntry)

Audit logs an audit entry as JSON to the standard log output. If JSON marshaling fails, it logs an error using the structured logger but continues execution.

func Fatal

func Fatal(msg string)

Fatal logs a message at Fatal level and then calls os.Exit(1).

func FatalF

func FatalF(format string, args ...any)

FatalF logs a formatted message at Fatal level and then calls os.Exit(1). It follows the printf formatting rules.

func FatalLn

func FatalLn(args ...any)

FatalLn logs a message at Fatal level with a line feed and then calls os.Exit(1).

func Log

func Log() *slog.Logger

Log returns a thread-safe singleton instance of slog.Logger configured for JSON output. If the logger hasn't been initialized, it creates a new instance with the log level specified by the environment. Subsequent calls return the same logger instance.

Types

type AuditAction

type AuditAction string
const AuditCreate AuditAction = "create"
const AuditDelete AuditAction = "delete"
const AuditEnter AuditAction = "enter"
const AuditFallback AuditAction = "fallback"
const AuditInitCheck AuditAction = "init-check"
const AuditList AuditAction = "list"
const AuditLogin AuditAction = "login"
const AuditRead AuditAction = "read"
const AuditUndelete AuditAction = "undelete"

type AuditEntry

type AuditEntry struct {
	// Id is a unique identifier for the audit trail
	TrailId string

	// Timestamp indicates when the audited action occurred
	Timestamp time.Time

	// UserId identifies the user who performed the action
	UserId string

	// Action describes what operation was performed
	Action AuditAction

	// Path is the URL path of the request
	Path string

	// Resource identifies the object or entity that was acted upon
	Resource string

	// SessionID links the action to a specific user session
	SessionID string

	// State represents the state of the resource after the action
	State AuditState

	// Err contains an error message if the action failed
	Err string

	// Duration is the time taken to process the action
	Duration time.Duration
}

AuditEntry represents a single audit log entry containing information about user actions within the system.

type AuditState

type AuditState string
const AuditCreated AuditState = "created"
const AuditErrored AuditState = "error"
const AuditSuccess AuditState = "success"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL