Documentation ¶
Index ¶
Constants ¶
View Source
const ( TimestampKey = "ts" ActorKey = "actor" ActionKey = "action" DescriptionKey = "desc" DetailsKey = "details" SeverityKey = "severity" )
View Source
const ( BaseCoverage = "BASE" AdvancedCoverage = "ADVANCED" FullCoverage = "FULL" )
Constants of coverage level which can be used to label and group audit log by their coverage level.
View Source
const ( FullCoverageLevel = slog.Level(-8) AdvancedCoverageLevel = slog.Level(2) BaseCoverageLevel = slog.Level(12) )
Leverage the slog level to define the coverage levels for easily setting the level and filtering. The higher the level, the more general the event. Those pre-defined levels can be found in the slog package (https://pkg.go.dev/log/slog#Level).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType string
ActionType is a categorical identifier used to give high-level insight as to the action type.
const ( ActionTypeCreate ActionType = "CREATE" ActionTypeDelete ActionType = "DELETE" ActionTypeDownload ActionType = "DOWNLOAD" ActionTypeLogin ActionType = "LOGIN" ActionTypeLogout ActionType = "LOGOUT" ActionTypeUnknown ActionType = "UNKNOWN" ActionTypeUpdate ActionType = "UPDATE" ActionTypeUpload ActionType = "UPLOAD" ActionTypeView ActionType = "VIEW" )
Constant ActionType identifiers which can be used to label and group audit log by their action type.
type Configuration ¶
type Configuration struct { // StorageDir is the directory to write logs to. StorageDir string // Filename is the file to write logs to. Backup log files will be retained // in the same directory. FileName string // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int }
type Logger ¶
type Logger interface { // LogBase adds an audit log entry to the log writer with base coverage level LogBase(severity Severity, actor string, action ActionType, description string, details any) // LogAdvanced adds an audit log entry to the log writer with advanced coverage level LogAdvanced(severity Severity, actor string, action ActionType, description string, details any) // LogFull adds an audit log entry to the log writer with full coverage level LogFull(severity Severity, actor string, action ActionType, description string, details any) }
Logger defines the interface for logging operations.
func InitLogger ¶
func InitLogger(owningServiceName string, coverageLevel string, logWriter io.Writer, config Configuration) Logger
InitLogger creates an instance of Logger
Click to show internal directories.
Click to hide internal directories.