Documentation
¶
Index ¶
- func ArchiveLogs(files []string) error
- func CheckLogSize(config Config) error
- func Client() *http.Client
- func CreateTarGz(archivePath string, files []string) error
- func DBus() *dbus.Conn
- func GetLogDirectorySize(directory string) (int64, error)
- func GetLogPath() string
- func GetServiceInfo() (int, string, string, error)
- func IsRunning() bool
- func RotateLogFile(logFilePath string) error
- func RotateLogFiles(files []string) error
- func Run() error
- func Server() *http.Server
- func Start(port string) error
- func Stop() error
- type Config
- type ConfigImpl
- func (c *ConfigImpl) Address() string
- func (c *ConfigImpl) BindAddress() string
- func (c *ConfigImpl) Format() string
- func (c *ConfigImpl) GetFormatter() interface{}
- func (c *ConfigImpl) GetInt(key string, defaultValue int) int
- func (c *ConfigImpl) GetString(key string, defaultValue string) string
- func (c *ConfigImpl) IdleTimeout() time.Duration
- func (c *ConfigImpl) Level() string
- func (c *ConfigImpl) Mode() interface{}
- func (c *ConfigImpl) NotifierManager() interface{}
- func (c *ConfigImpl) Output() string
- func (c *ConfigImpl) PidFile() string
- func (c *ConfigImpl) Port() string
- func (c *ConfigImpl) ReadTimeout() time.Duration
- func (c *ConfigImpl) SetFormat(format interface{})
- func (c *ConfigImpl) SetLevel(VLevel interface{})
- func (c *ConfigImpl) SetOutput(configPath string)
- func (c *ConfigImpl) WriteTimeout() time.Duration
- type ConfigManager
- type ConfigManagerImpl
- func (cm *ConfigManagerImpl) Address() string
- func (cm *ConfigManagerImpl) BindAddress() string
- func (cm *ConfigManagerImpl) Format() string
- func (cm *ConfigManagerImpl) GetConfig() Config
- func (cm *ConfigManagerImpl) GetConfigPath() string
- func (cm *ConfigManagerImpl) GetFormatter() interface{}
- func (cm *ConfigManagerImpl) GetInt(key string, value int) int
- func (cm *ConfigManagerImpl) GetPidPath() string
- func (cm *ConfigManagerImpl) IdleTimeout() time.Duration
- func (cm *ConfigManagerImpl) Level() string
- func (cm *ConfigManagerImpl) LoadConfig() (Config, error)
- func (cm *ConfigManagerImpl) Mode() interface{}
- func (cm *ConfigManagerImpl) NotifierManager() interface{}
- func (cm *ConfigManagerImpl) Output() string
- func (cm *ConfigManagerImpl) PidFile() string
- func (cm *ConfigManagerImpl) Port() string
- func (cm *ConfigManagerImpl) ReadTimeout() time.Duration
- func (cm *ConfigManagerImpl) SetFormat(format interface{})
- func (cm *ConfigManagerImpl) SetLevel(VLevel interface{})
- func (cm *ConfigManagerImpl) SetOutput(output string)
- func (cm *ConfigManagerImpl) WriteTimeout() time.Duration
- type DBusNotifier
- type DefaultWriter
- type FileLogReader
- type HTTPNotifier
- type JSONFormatter
- type LogEntry
- func (le *LogEntry) AddMetadata(key string, value interface{}) LogzEntry
- func (le *LogEntry) AddTag(key, value string) LogzEntry
- func (le *LogEntry) GetContext() string
- func (le *LogEntry) GetLevel() LogLevel
- func (le *LogEntry) GetMessage() string
- func (le *LogEntry) GetMetadata() map[string]interface{}
- func (le *LogEntry) GetSource() string
- func (le *LogEntry) GetTimestamp() time.Time
- func (le *LogEntry) String() string
- func (le *LogEntry) Validate() error
- func (le *LogEntry) WithContext(context string) LogzEntry
- func (le *LogEntry) WithHostname(hostname string) LogzEntry
- func (le *LogEntry) WithLevel(level LogLevel) LogzEntry
- func (le *LogEntry) WithMessage(message string) LogzEntry
- func (le *LogEntry) WithProcessID(pid int) LogzEntry
- func (le *LogEntry) WithSeverity(severity int) LogzEntry
- func (le *LogEntry) WithSource(source string) LogzEntry
- func (le *LogEntry) WithTraceID(traceID string) LogzEntry
- type LogFormat
- type LogFormatter
- type LogLevel
- type LogMode
- type LogMultiWriter
- type LogReader
- type LogWriter
- type LogzConfig
- type LogzCore
- type LogzCoreImpl
- func (l *LogzCoreImpl) DebugCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) ErrorCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) FatalCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) GetConfig() interface{}
- func (l *LogzCoreImpl) GetLevel() interface{}
- func (l *LogzCoreImpl) GetMode() interface{}
- func (l *LogzCoreImpl) GetWriter() interface{}
- func (l *LogzCoreImpl) InfoCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) NoticeCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) SetConfig(config interface{})
- func (l *LogzCoreImpl) SetLevel(level interface{})
- func (l *LogzCoreImpl) SetMetadata(key string, value interface{})
- func (l *LogzCoreImpl) SetWriter(writer any)
- func (l *LogzCoreImpl) SuccessCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) TraceCtx(msg string, ctx map[string]interface{})
- func (l *LogzCoreImpl) WarnCtx(msg string, ctx map[string]interface{})
- type LogzEntry
- type LogzLogger
- type Metric
- type MultiWriter
- type Notifier
- type NotifierImpl
- type NotifierManager
- type NotifierManagerImpl
- func (nm *NotifierManagerImpl) AddNotifier(name string, notifier Notifier)
- func (nm *NotifierManagerImpl) DBusClient() *dbus.Conn
- func (nm *NotifierManagerImpl) GetNotifier(name string) (Notifier, bool)
- func (nm *NotifierManagerImpl) ListNotifiers() []string
- func (nm *NotifierManagerImpl) RemoveNotifier(name string)
- func (nm *NotifierManagerImpl) UpdateFromConfig() error
- func (nm *NotifierManagerImpl) WebClient() *http.Client
- func (nm *NotifierManagerImpl) WebServer() *http.Server
- type PrometheusManager
- func (pm *PrometheusManager) AddMetric(name string, value float64, metadata map[string]string)
- func (pm *PrometheusManager) Disable()
- func (pm *PrometheusManager) Enable(port string)
- func (pm *PrometheusManager) GetMetrics() map[string]float64
- func (pm *PrometheusManager) IncrementMetric(name string, delta float64)
- func (pm *PrometheusManager) IsEnabled() bool
- func (pm *PrometheusManager) ListMetrics()
- func (pm *PrometheusManager) RemoveMetric(name string)
- func (pm *PrometheusManager) SetExportWhitelist(metrics []string)
- type TextFormatter
- type ZMQNotifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArchiveLogs ¶
ArchiveLogs archives old logs into a zip file
func CheckLogSize ¶
CheckLogSize checks and manages the size of the logs
func CreateTarGz ¶
CreateTarGz creates a tar.gz file from the logs
func GetLogDirectorySize ¶
func GetLogPath ¶
func GetLogPath() string
func GetServiceInfo ¶
GetServiceInfo retrieves the PID, port, and PID file path of the running service.
func RotateLogFile ¶
RotateLogFile compresses a single log file
func RotateLogFiles ¶
RotateLogFiles compresses and recreates the log files
Types ¶
type Config ¶
type Config interface { Port() string BindAddress() string Address() string PidFile() string ReadTimeout() time.Duration WriteTimeout() time.Duration IdleTimeout() time.Duration Output() string SetOutput(configPath string) NotifierManager() interface{} Mode() interface{} Level() string SetLevel(VLevel interface{}) Format() string SetFormat(LogFormat interface{}) GetInt(key string, value int) int GetFormatter() interface{} }
Config interface defines the methods to access configuration settings.
type ConfigImpl ¶
type ConfigImpl struct { // Config is a constraint to implement Config interface Config VlLevel LogLevel VlFormat LogFormat VlPort string VlBindAddress string VlAddress string VlPidFile string VlReadTimeout time.Duration VlWriteTimeout time.Duration VlIdleTimeout time.Duration VlOutput string VlNotifierManager NotifierManager VlMode LogMode }
ConfigImpl implements the Config interface and holds the configuration values.
func (*ConfigImpl) Address ¶
func (c *ConfigImpl) Address() string
func (*ConfigImpl) BindAddress ¶
func (c *ConfigImpl) BindAddress() string
func (*ConfigImpl) Format ¶
func (c *ConfigImpl) Format() string
func (*ConfigImpl) GetFormatter ¶
func (c *ConfigImpl) GetFormatter() interface{}
func (*ConfigImpl) GetString ¶
func (c *ConfigImpl) GetString(key string, defaultValue string) string
func (*ConfigImpl) IdleTimeout ¶
func (c *ConfigImpl) IdleTimeout() time.Duration
func (*ConfigImpl) Level ¶
func (c *ConfigImpl) Level() string
func (*ConfigImpl) Mode ¶
func (c *ConfigImpl) Mode() interface{}
func (*ConfigImpl) NotifierManager ¶
func (c *ConfigImpl) NotifierManager() interface{}
func (*ConfigImpl) Output ¶
func (c *ConfigImpl) Output() string
func (*ConfigImpl) PidFile ¶
func (c *ConfigImpl) PidFile() string
func (*ConfigImpl) Port ¶
func (c *ConfigImpl) Port() string
func (*ConfigImpl) ReadTimeout ¶
func (c *ConfigImpl) ReadTimeout() time.Duration
func (*ConfigImpl) SetFormat ¶
func (c *ConfigImpl) SetFormat(format interface{})
func (*ConfigImpl) SetLevel ¶
func (c *ConfigImpl) SetLevel(VLevel interface{})
func (*ConfigImpl) SetOutput ¶
func (c *ConfigImpl) SetOutput(configPath string)
func (*ConfigImpl) WriteTimeout ¶
func (c *ConfigImpl) WriteTimeout() time.Duration
type ConfigManager ¶
type ConfigManager interface { GetConfig() Config GetPidPath() string GetConfigPath() string Output() string SetOutput(configPath string) LoadConfig() (Config, error) }
ConfigManager interface defines methods to manage configuration.
func NewConfigManager ¶
func NewConfigManager() *ConfigManager
NewConfigManager creates a new instance of ConfigManager.
type ConfigManagerImpl ¶
ConfigManagerImpl implements the ConfigManager interface.
func (*ConfigManagerImpl) Address ¶
func (cm *ConfigManagerImpl) Address() string
func (*ConfigManagerImpl) BindAddress ¶
func (cm *ConfigManagerImpl) BindAddress() string
func (*ConfigManagerImpl) Format ¶
func (cm *ConfigManagerImpl) Format() string
func (*ConfigManagerImpl) GetConfig ¶
func (cm *ConfigManagerImpl) GetConfig() Config
func (*ConfigManagerImpl) GetConfigPath ¶
func (cm *ConfigManagerImpl) GetConfigPath() string
GetConfigPath returns the path to the configuration file.
func (*ConfigManagerImpl) GetFormatter ¶
func (cm *ConfigManagerImpl) GetFormatter() interface{}
GetFormatter returns the formatter for the core.
func (*ConfigManagerImpl) GetPidPath ¶
func (cm *ConfigManagerImpl) GetPidPath() string
GetPidPath returns the path to the PID file.
func (*ConfigManagerImpl) IdleTimeout ¶
func (cm *ConfigManagerImpl) IdleTimeout() time.Duration
func (*ConfigManagerImpl) Level ¶
func (cm *ConfigManagerImpl) Level() string
func (*ConfigManagerImpl) LoadConfig ¶
func (cm *ConfigManagerImpl) LoadConfig() (Config, error)
LoadConfig loads the configuration from the file and returns a Config instance.
func (*ConfigManagerImpl) Mode ¶
func (cm *ConfigManagerImpl) Mode() interface{}
func (*ConfigManagerImpl) NotifierManager ¶
func (cm *ConfigManagerImpl) NotifierManager() interface{}
func (*ConfigManagerImpl) Output ¶
func (cm *ConfigManagerImpl) Output() string
Output returns the path to the configuration file.
func (*ConfigManagerImpl) PidFile ¶
func (cm *ConfigManagerImpl) PidFile() string
func (*ConfigManagerImpl) Port ¶
func (cm *ConfigManagerImpl) Port() string
func (*ConfigManagerImpl) ReadTimeout ¶
func (cm *ConfigManagerImpl) ReadTimeout() time.Duration
func (*ConfigManagerImpl) SetFormat ¶
func (cm *ConfigManagerImpl) SetFormat(format interface{})
func (*ConfigManagerImpl) SetLevel ¶
func (cm *ConfigManagerImpl) SetLevel(VLevel interface{})
func (*ConfigManagerImpl) SetOutput ¶
func (cm *ConfigManagerImpl) SetOutput(output string)
SetOutput sets the path to the default log file.
func (*ConfigManagerImpl) WriteTimeout ¶
func (cm *ConfigManagerImpl) WriteTimeout() time.Duration
type DBusNotifier ¶
type DBusNotifier struct {
NotifierImpl
}
DBusNotifier is a notifier that sends DBus notifications.
func NewDBusNotifier ¶
func NewDBusNotifier() *DBusNotifier
NewDBusNotifier creates a new DBusNotifier instance.
func (*DBusNotifier) Notify ¶
func (n *DBusNotifier) Notify(entry LogzEntry) error
Notify sends a DBus notification.
type DefaultWriter ¶
type DefaultWriter[T any] struct { // contains filtered or unexported fields }
NewDefaultWriter creates a new instance of DefaultWriter. Takes an io.Writer and a LogFormatter as parameters.
func NewDefaultWriter ¶
func NewDefaultWriter[T any](out io.Writer, formatter LogFormatter) *DefaultWriter[T]
NewDefaultWriter cria um novo VWriter usando generics.
func (*DefaultWriter[T]) Write ¶
func (w *DefaultWriter[T]) Write(entry T) error
Write aceita qualquer tipo de entrada T e a processa.
type FileLogReader ¶
type FileLogReader struct {
// contains filtered or unexported fields
}
FileLogReader implements the LogReader interface by reading from a file.
func NewFileLogReader ¶
func NewFileLogReader() *FileLogReader
NewFileLogReader creates a new instance of FileLogReader. The polling interval is read from the LOGZ_TAIL_POLL_INTERVAL environment variable (in milliseconds), or defaults to 500ms.
func (*FileLogReader) Tail ¶
func (fr *FileLogReader) Tail(filePath string, stopChan <-chan struct{}) error
Tail follows the log file from the end and prints new lines as they are added. The stopChan channel allows interrupting the operation (e.g., via Ctrl+C).
type HTTPNotifier ¶
type HTTPNotifier struct {
NotifierImpl
}
HTTPNotifier is a notifier that sends HTTP notifications.
func NewHTTPNotifier ¶
func NewHTTPNotifier(webhookURL, authToken string) *HTTPNotifier
NewHTTPNotifier creates a new HTTPNotifier instance.
func (*HTTPNotifier) Notify ¶
func (n *HTTPNotifier) Notify(entry LogzEntry) error
Notify sends an HTTP notification.
type LogEntry ¶
type LogEntry struct { Timestamp time.Time `json:"timestamp"` // The time when the log entry was created. Level LogLevel `json:"VLevel"` // The severity VLevel of the log entry. Source string `json:"source"` // The source of the log entry. Context string `json:"context,omitempty"` // Additional context for the log entry. Message string `json:"message"` // The log message. Tags map[string]string `json:"tags,omitempty"` // Optional tags associated with the log entry. Metadata map[string]interface{} `json:"VMetadata,omitempty"` // Optional VMetadata associated with the log entry. ProcessID int `json:"pid,omitempty"` // The process ID associated with the log entry. Hostname string `json:"hostname,omitempty"` // The hostname where the log entry was created. Severity int `json:"severity"` // The severity VLevel as an integer. TraceID string `json:"trace_id,omitempty"` // Optional trace ID for tracing logs. Caller string `json:"caller,omitempty"` // The caller of the log entry. }
LogEntry represents a single log entry with various attributes.
func (*LogEntry) AddMetadata ¶
AddMetadata adds VMetadata to the LogEntry.
func (*LogEntry) GetContext ¶
GetContext returns the context of the LogEntry.
func (*LogEntry) GetMessage ¶
GetMessage returns the message of the LogEntry.
func (*LogEntry) GetMetadata ¶
GetMetadata returns the VMetadata of the LogEntry.
func (*LogEntry) GetTimestamp ¶
GetTimestamp returns the timestamp of the LogEntry.
func (*LogEntry) WithContext ¶
WithContext sets the context for the LogEntry.
func (*LogEntry) WithHostname ¶
WithHostname sets the hostname for the LogEntry.
func (*LogEntry) WithMessage ¶
WithMessage sets the message for the LogEntry.
func (*LogEntry) WithProcessID ¶
WithProcessID sets the process ID for the LogEntry.
func (*LogEntry) WithSeverity ¶
WithSeverity sets the severity VLevel for the LogEntry.
func (*LogEntry) WithSource ¶
WithSource sets the source for the LogEntry.
func (*LogEntry) WithTraceID ¶
WithTraceID sets the trace ID for the LogEntry.
type LogFormatter ¶
type LogFormatter interface { // Format converts a log entry to a formatted string. // Returns the formatted string and an error if formatting fails. Format(entry LogzEntry) (string, error) }
LogFormatter defines the contract for formatting log entries.
type LogMultiWriter ¶
type LogReader ¶
type LogReader interface { // Tail reads the log file in real-time and sends the new lines to the // provided VWriter or prints them to the terminal. The operation can be interrupted // by sending a signal through the stopChan channel. Tail(filePath string, stopChan <-chan struct{}) error }
LogReader defines the contract for reading logs.
type LogzConfig ¶
type LogzConfig struct { LogLevel string LogFormat string LogFilePath string ReadTimeout time.Duration WriteTimeout time.Duration PidFile string }
LogzConfig specific to Logz
type LogzCore ¶
type LogzCore interface { // SetMetadata sets a VMetadata key-value pair. // If the key is empty, it returns all VMetadata. // Returns the value and a boolean indicating if the key exists. SetMetadata(string, interface{}) // TraceCtx logs a trace message with context. // Method signature: // TraceCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. TraceCtx(string, map[string]interface{}) // NoticeCtx logs a notice message with context. // Method signature: // NoticeCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. NoticeCtx(string, map[string]interface{}) // SuccessCtx logs a success message with context. // Method signature: // SuccessCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. SuccessCtx(string, map[string]interface{}) // DebugCtx logs a debug message with context. // Method signature: // DebugCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. DebugCtx(string, map[string]interface{}) // InfoCtx logs an informational message with context. // Method signature: // InfoCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. InfoCtx(string, map[string]interface{}) // WarnCtx logs a warning message with context. // Method signature: // WarnCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. WarnCtx(string, map[string]interface{}) // ErrorCtx logs an error message with context. // Method signature: // ErrorCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. ErrorCtx(string, map[string]interface{}) // FatalCtx logs a fatal message with context and exits the application. // Method signature: // FatalCtx(message string, context map[string]interface{}) // The message is a string. // The context is a map of key-value pairs. FatalCtx(string, map[string]interface{}) // GetWriter returns the current VWriter. // Method signature: // GetWriter() interface{} // The VWriter is an interface that implements the LogWriter interface. GetWriter() interface{} // SetWriter sets the VWriter. // Method signature: // SetWriter(VWriter interface{}) // The VWriter is an interface that implements the LogWriter interface or io.Writer. SetWriter(interface{}) // GetConfig returns the current configuration. // Method signature: // GetConfig() interface{} // The configuration is an interface that implements the Config interface. GetConfig() interface{} // SetConfig sets the configuration. SetConfig(interface{}) // SetFormat sets the format for the log entries. SetFormat(interface{}) }
LogzCore is the interface with the basic methods of the existing il.
type LogzCoreImpl ¶
type LogzCoreImpl struct { // LogzLogger is a constraint to implement this interface LogzLogger // Logger is a promoted global Go Logger log.Logger VLevel LogLevel VWriter LogWriter[any] VConfig Config VMetadata map[string]interface{} VMode LogMode // Mode control: service or standalone Mu sync.RWMutex // contains filtered or unexported fields }
LogzCoreImpl represents a core with configuration and VMetadata.
func (*LogzCoreImpl) DebugCtx ¶
func (l *LogzCoreImpl) DebugCtx(msg string, ctx map[string]interface{})
DebugCtx logs a debug message with context.
func (*LogzCoreImpl) ErrorCtx ¶
func (l *LogzCoreImpl) ErrorCtx(msg string, ctx map[string]interface{})
ErrorCtx logs an error message with context.
func (*LogzCoreImpl) FatalCtx ¶
func (l *LogzCoreImpl) FatalCtx(msg string, ctx map[string]interface{})
FatalCtx logs a fatal message with context and terminates the process.
func (*LogzCoreImpl) GetConfig ¶
func (l *LogzCoreImpl) GetConfig() interface{}
func (*LogzCoreImpl) GetLevel ¶
func (l *LogzCoreImpl) GetLevel() interface{}
func (*LogzCoreImpl) GetMode ¶
func (l *LogzCoreImpl) GetMode() interface{}
func (*LogzCoreImpl) GetWriter ¶
func (l *LogzCoreImpl) GetWriter() interface{}
func (*LogzCoreImpl) InfoCtx ¶
func (l *LogzCoreImpl) InfoCtx(msg string, ctx map[string]interface{})
InfoCtx logs an info message with context.
func (*LogzCoreImpl) NoticeCtx ¶
func (l *LogzCoreImpl) NoticeCtx(msg string, ctx map[string]interface{})
NoticeCtx logs a notice message with context.
func (*LogzCoreImpl) SetConfig ¶
func (l *LogzCoreImpl) SetConfig(config interface{})
func (*LogzCoreImpl) SetLevel ¶
func (l *LogzCoreImpl) SetLevel(level interface{})
func (*LogzCoreImpl) SetMetadata ¶
func (l *LogzCoreImpl) SetMetadata(key string, value interface{})
SetMetadata sets a VMetadata key-value pair for the LogzCoreImpl.
func (*LogzCoreImpl) SetWriter ¶
func (l *LogzCoreImpl) SetWriter(writer any)
func (*LogzCoreImpl) SuccessCtx ¶
func (l *LogzCoreImpl) SuccessCtx(msg string, ctx map[string]interface{})
SuccessCtx logs a success message with context.
func (*LogzCoreImpl) TraceCtx ¶
func (l *LogzCoreImpl) TraceCtx(msg string, ctx map[string]interface{})
TraceCtx logs a trace message with context.
func (*LogzCoreImpl) WarnCtx ¶
func (l *LogzCoreImpl) WarnCtx(msg string, ctx map[string]interface{})
WarnCtx logs a warning message with context.
type LogzEntry ¶
type LogzEntry interface { // WithLevel sets the log VLevel for the LogEntry. WithLevel(level LogLevel) LogzEntry // WithSource sets the source for the LogEntry. WithSource(source string) LogzEntry // WithContext sets the context for the LogEntry. WithContext(context string) LogzEntry // WithMessage sets the message for the LogEntry. WithMessage(message string) LogzEntry // WithProcessID sets the process ID for the LogEntry. WithProcessID(pid int) LogzEntry // WithHostname sets the hostname for the LogEntry. WithHostname(hostname string) LogzEntry // WithSeverity sets the severity VLevel for the LogEntry. WithSeverity(severity int) LogzEntry // WithTraceID sets the trace ID for the LogEntry. WithTraceID(traceID string) LogzEntry // AddTag adds a tag to the LogEntry. AddTag(key, value string) LogzEntry // AddMetadata adds VMetadata to the LogEntry. AddMetadata(key string, value interface{}) LogzEntry // GetMetadata returns the VMetadata of the LogEntry. GetMetadata() map[string]interface{} // GetContext returns the context of the LogEntry. GetContext() string // GetTimestamp returns the timestamp of the LogEntry. GetTimestamp() time.Time // GetMessage returns the message of the LogEntry. GetMessage() string // GetLevel returns the log VLevel of the LogEntry. GetLevel() LogLevel // GetSource returns the source of the LogEntry. GetSource() string // Validate checks if the LogEntry has all required fields set. Validate() error // String returns a string representation of the LogEntry. String() string }
LogzEntry represents a single log entry with various attributes.
func NewLogEntry ¶
func NewLogEntry() LogzEntry
NewLogEntry creates a new instance of LogEntry with the current timestamp and initialized maps.
type LogzLogger ¶
type LogzLogger interface { LogzCore // GetLevel returns the current log VLevel. // Method signature: // GetLevel() interface{} GetLevel() interface{} // SetLevel sets the log VLevel. // Method signature: // SetLevel(VLevel interface{}) // The VLevel is an LogLevel type or string. SetLevel(interface{}) }
LogzLogger combines the existing core with the standard Go log methods.
func NewLogger ¶
func NewLogger(prefix string) LogzLogger
NewLogger creates a new instance of LogzCoreImpl with the provided configuration.
type Metric ¶
type Metric struct { Value float64 `json:"value"` Metadata map[string]string `json:"VMetadata,omitempty"` }
Metric represents a single Prometheus metric with a value and optional VMetadata.
type MultiWriter ¶
type MultiWriter[T any] struct { // contains filtered or unexported fields }
func (*MultiWriter[T]) AddWriter ¶
func (mw *MultiWriter[T]) AddWriter(w LogWriter[T])
func (*MultiWriter[T]) GetWriters ¶
func (mw *MultiWriter[T]) GetWriters() []LogWriter[T]
func (*MultiWriter[T]) Write ¶
func (mw *MultiWriter[T]) Write(entry T) error
type Notifier ¶
type Notifier interface { // Notify sends a log entry notification. Notify(entry LogzEntry) error // Enable activates the notifier. Enable() // Disable deactivates the notifier. Disable() // Enabled checks if the notifier is active. Enabled() bool // WebServer returns the HTTP server instance. WebServer() *http.Server // WebClient returns the HTTP client instance. WebClient() *http.Client // DBusClient returns the DBus connection instance. DBusClient() *dbus.Conn }
Notifier defines the interface for a log notifier.
func NewNotifier ¶
func NewNotifier(manager NotifierManager, enabled bool, webhookURL, httpMethod, authToken, logLevel, wsEndpoint string, whitelist []string) Notifier
NewNotifier creates a new NotifierImpl instance.
type NotifierImpl ¶
type NotifierImpl struct { NotifierManager NotifierManager // Manager for notifier instances. EnabledFlag bool // Flag indicating if the notifier is enabled. WebhookURL string // URL for webhook notifications. HttpMethod string // HTTP method for webhook notifications. AuthToken string // Authentication token for notifications. LogLevel string // Log VLevel for filtering notifications. WsEndpoint string // WebSocket endpoint for notifications. Whitelist []string // Whitelist of sources for notifications. }
NotifierImpl is the implementation of the Notifier interface.
func (*NotifierImpl) DBusClient ¶
func (n *NotifierImpl) DBusClient() *dbus.Conn
DBusClient returns the DBus connection instance.
func (*NotifierImpl) Enabled ¶
func (n *NotifierImpl) Enabled() bool
Enabled checks if the notifier is active.
func (*NotifierImpl) Notify ¶
func (n *NotifierImpl) Notify(entry LogzEntry) error
Notify sends a log entry notification based on the configured settings.
func (*NotifierImpl) WebClient ¶
func (n *NotifierImpl) WebClient() *http.Client
WebClient returns the HTTP client instance.
func (*NotifierImpl) WebServer ¶
func (n *NotifierImpl) WebServer() *http.Server
WebServer returns the HTTP server instance.
type NotifierManager ¶
type NotifierManager interface { // WebServer returns the HTTP server instance. WebServer() *http.Server // WebClient returns the HTTP client instance. WebClient() *http.Client // DBusClient returns the DBus connection instance. DBusClient() *dbus.Conn // AddNotifier adds or updates a notifier with the given name. AddNotifier(name string, notifier Notifier) // RemoveNotifier removes the notifier with the given name. RemoveNotifier(name string) // GetNotifier retrieves the notifier with the given name. GetNotifier(name string) (Notifier, bool) // ListNotifiers lists all registered notifier names. ListNotifiers() []string // UpdateFromConfig updates notifiers dynamically based on the provided configuration. UpdateFromConfig() error }
NotifierManager defines the interface for managing notifiers.
func NewNotifierManager ¶
func NewNotifierManager(notifiers map[string]Notifier) NotifierManager
NewNotifierManager creates a new instance of NotifierManagerImpl.
type NotifierManagerImpl ¶
type NotifierManagerImpl struct {
// contains filtered or unexported fields
}
NotifierManagerImpl is the implementation of the NotifierManager interface.
func (*NotifierManagerImpl) AddNotifier ¶
func (nm *NotifierManagerImpl) AddNotifier(name string, notifier Notifier)
AddNotifier adds or updates a notifier with the given name.
func (*NotifierManagerImpl) DBusClient ¶
func (nm *NotifierManagerImpl) DBusClient() *dbus.Conn
DBusClient returns the DBus connection instance.
func (*NotifierManagerImpl) GetNotifier ¶
func (nm *NotifierManagerImpl) GetNotifier(name string) (Notifier, bool)
GetNotifier retrieves the notifier with the given name.
func (*NotifierManagerImpl) ListNotifiers ¶
func (nm *NotifierManagerImpl) ListNotifiers() []string
ListNotifiers lists all registered notifier names.
func (*NotifierManagerImpl) RemoveNotifier ¶
func (nm *NotifierManagerImpl) RemoveNotifier(name string)
RemoveNotifier removes the notifier with the given name.
func (*NotifierManagerImpl) UpdateFromConfig ¶
func (nm *NotifierManagerImpl) UpdateFromConfig() error
UpdateFromConfig updates notifiers dynamically based on the provided configuration.
func (*NotifierManagerImpl) WebClient ¶
func (nm *NotifierManagerImpl) WebClient() *http.Client
WebClient returns the HTTP client instance.
func (*NotifierManagerImpl) WebServer ¶
func (nm *NotifierManagerImpl) WebServer() *http.Server
WebServer returns the HTTP server instance.
type PrometheusManager ¶
type PrometheusManager struct {
// contains filtered or unexported fields
}
PrometheusManager manages Prometheus metrics, including enabling/disabling the HTTP server, loading/saving metrics, and handling metric operations.
func GetPrometheusManager ¶
func GetPrometheusManager() *PrometheusManager
GetPrometheusManager returns the singleton instance of PrometheusManager, initializing it if necessary.
func (*PrometheusManager) AddMetric ¶
func (pm *PrometheusManager) AddMetric(name string, value float64, metadata map[string]string)
AddMetric adds or updates a metric with the given name, value, and VMetadata.
func (*PrometheusManager) Disable ¶
func (pm *PrometheusManager) Disable()
Disable stops the Prometheus HTTP server and disables metric exposure.
func (*PrometheusManager) Enable ¶
func (pm *PrometheusManager) Enable(port string)
Enable starts the Prometheus HTTP server on the specified port to expose metrics.
func (*PrometheusManager) GetMetrics ¶
func (pm *PrometheusManager) GetMetrics() map[string]float64
GetMetrics returns the current metrics, filtered by the export whitelist if defined.
func (*PrometheusManager) IncrementMetric ¶
func (pm *PrometheusManager) IncrementMetric(name string, delta float64)
IncrementMetric increments the value of a metric by the given delta.
func (*PrometheusManager) IsEnabled ¶
func (pm *PrometheusManager) IsEnabled() bool
IsEnabled returns whether the Prometheus metrics exposure is enabled.
func (*PrometheusManager) ListMetrics ¶
func (pm *PrometheusManager) ListMetrics()
ListMetrics prints all registered metrics to the console.
func (*PrometheusManager) RemoveMetric ¶
func (pm *PrometheusManager) RemoveMetric(name string)
RemoveMetric removes a metric with the given name.
func (*PrometheusManager) SetExportWhitelist ¶
func (pm *PrometheusManager) SetExportWhitelist(metrics []string)
SetExportWhitelist sets the list of metrics that are allowed to be exported to Prometheus.
type ZMQNotifier ¶
type ZMQNotifier struct {
NotifierImpl
}
ZMQNotifier is a notifier that sends WebSocket notifications.
func NewZMQNotifier ¶
func NewZMQNotifier(endpoint string) *ZMQNotifier
NewZMQNotifier creates a new ZMQNotifier instance.
func (*ZMQNotifier) Notify ¶
func (n *ZMQNotifier) Notify(entry LogzEntry) error
Temporarily disabled due to external dependency on zmq4 Uncomment and ensure the required libraries are installed if needed in the future Notify sends a WebSocket notification.