Event logging
This commit is contained in:
@@ -7,12 +7,13 @@ import (
|
||||
|
||||
// Config represents the application configuration
|
||||
type Config struct {
|
||||
Server ServerConfig `json:"server"`
|
||||
WhatsApp []WhatsAppConfig `json:"whatsapp"`
|
||||
Hooks []Hook `json:"hooks"`
|
||||
Database DatabaseConfig `json:"database,omitempty"`
|
||||
Media MediaConfig `json:"media"`
|
||||
LogLevel string `json:"log_level"`
|
||||
Server ServerConfig `json:"server"`
|
||||
WhatsApp []WhatsAppConfig `json:"whatsapp"`
|
||||
Hooks []Hook `json:"hooks"`
|
||||
Database DatabaseConfig `json:"database,omitempty"`
|
||||
Media MediaConfig `json:"media"`
|
||||
EventLogger EventLoggerConfig `json:"event_logger,omitempty"`
|
||||
LogLevel string `json:"log_level"`
|
||||
}
|
||||
|
||||
// ServerConfig holds server-specific configuration
|
||||
@@ -47,12 +48,13 @@ type Hook struct {
|
||||
|
||||
// DatabaseConfig holds database connection information
|
||||
type DatabaseConfig struct {
|
||||
Type string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Database string `json:"database"`
|
||||
Type string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Database string `json:"database"`
|
||||
SQLitePath string `json:"sqlite_path,omitempty"` // Path to SQLite database file
|
||||
}
|
||||
|
||||
// MediaConfig holds media storage and delivery configuration
|
||||
@@ -62,6 +64,18 @@ type MediaConfig struct {
|
||||
BaseURL string `json:"base_url,omitempty"` // Base URL for media links
|
||||
}
|
||||
|
||||
// EventLoggerConfig holds event logging configuration
|
||||
type EventLoggerConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Targets []string `json:"targets"` // "file", "sqlite", "postgres"
|
||||
|
||||
// File-based logging
|
||||
FileDir string `json:"file_dir,omitempty"` // Base directory for event files
|
||||
|
||||
// Database logging (uses main Database config for connection)
|
||||
TableName string `json:"table_name,omitempty"` // Table name for event logs (default: "event_logs")
|
||||
}
|
||||
|
||||
// Load reads configuration from a file
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
@@ -90,6 +104,15 @@ func Load(path string) (*Config, error) {
|
||||
if cfg.Media.Mode == "" {
|
||||
cfg.Media.Mode = "link"
|
||||
}
|
||||
if cfg.EventLogger.FileDir == "" {
|
||||
cfg.EventLogger.FileDir = "./data/events"
|
||||
}
|
||||
if cfg.EventLogger.TableName == "" {
|
||||
cfg.EventLogger.TableName = "event_logs"
|
||||
}
|
||||
if cfg.Database.SQLitePath == "" {
|
||||
cfg.Database.SQLitePath = "./data/events.db"
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user