core

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveLogs

func ArchiveLogs(files []string) error

ArchiveLogs archives old logs into a zip file

func CheckLogSize

func CheckLogSize(config Config) error

CheckLogSize checks and manages the size of the logs

func Client

func Client() *http.Client

Client returns the HTTP client instance.

func CreateTarGz

func CreateTarGz(archivePath string, files []string) error

CreateTarGz creates a tar.gz file from the logs

func DBus

func DBus() *dbus.Conn

DBus returns the DBus connection instance.

func GetLogDirectorySize

func GetLogDirectorySize(directory string) (int64, error)

func GetLogPath

func GetLogPath() string

func GetServiceInfo

func GetServiceInfo() (int, string, string, error)

GetServiceInfo retrieves the PID, port, and PID file path of the running service.

func IsRunning

func IsRunning() bool

IsRunning checks if the service is currently running.

func RotateLogFile

func RotateLogFile(logFilePath string) error

RotateLogFile compresses a single log file

func RotateLogFiles

func RotateLogFiles(files []string) error

RotateLogFiles compresses and recreates the log files

func Run

func Run() error

Run starts the logging service.

func Server

func Server() *http.Server

Server returns the HTTP server instance.

func Start

func Start(port string) error

Start initiates the logging service on the specified port.

func Stop

func Stop() error

Stop terminates the running logging service.

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) GetInt

func (c *ConfigImpl) GetInt(key string, defaultValue int) int

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

type ConfigManagerImpl struct {
	VConfig Config
	Mu      sync.RWMutex
}

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) GetInt

func (cm *ConfigManagerImpl) GetInt(key string, value int) int

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 JSONFormatter

type JSONFormatter struct{}

JSONFormatter formats the log in JSON format.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(entry LogzEntry) (string, error)

Format converts the log entry to JSON. Returns the JSON string and an error if marshalling fails.

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

func (le *LogEntry) AddMetadata(key string, value interface{}) LogzEntry

AddMetadata adds VMetadata to the LogEntry.

func (*LogEntry) AddTag

func (le *LogEntry) AddTag(key, value string) LogzEntry

AddTag adds a tag to the LogEntry.

func (*LogEntry) GetContext

func (le *LogEntry) GetContext() string

GetContext returns the context of the LogEntry.

func (*LogEntry) GetLevel

func (le *LogEntry) GetLevel() LogLevel

GetLevel returns the log VLevel of the LogEntry.

func (*LogEntry) GetMessage

func (le *LogEntry) GetMessage() string

GetMessage returns the message of the LogEntry.

func (*LogEntry) GetMetadata

func (le *LogEntry) GetMetadata() map[string]interface{}

GetMetadata returns the VMetadata of the LogEntry.

func (*LogEntry) GetSource

func (le *LogEntry) GetSource() string

GetSource returns the source of the LogEntry.

func (*LogEntry) GetTimestamp

func (le *LogEntry) GetTimestamp() time.Time

GetTimestamp returns the timestamp of the LogEntry.

func (*LogEntry) String

func (le *LogEntry) String() string

String returns a string representation of the LogEntry.

func (*LogEntry) Validate

func (le *LogEntry) Validate() error

Validate checks if the LogEntry has all required fields set.

func (*LogEntry) WithContext

func (le *LogEntry) WithContext(context string) LogzEntry

WithContext sets the context for the LogEntry.

func (*LogEntry) WithHostname

func (le *LogEntry) WithHostname(hostname string) LogzEntry

WithHostname sets the hostname for the LogEntry.

func (*LogEntry) WithLevel

func (le *LogEntry) WithLevel(level LogLevel) LogzEntry

WithLevel sets the log VLevel for the LogEntry.

func (*LogEntry) WithMessage

func (le *LogEntry) WithMessage(message string) LogzEntry

WithMessage sets the message for the LogEntry.

func (*LogEntry) WithProcessID

func (le *LogEntry) WithProcessID(pid int) LogzEntry

WithProcessID sets the process ID for the LogEntry.

func (*LogEntry) WithSeverity

func (le *LogEntry) WithSeverity(severity int) LogzEntry

WithSeverity sets the severity VLevel for the LogEntry.

func (*LogEntry) WithSource

func (le *LogEntry) WithSource(source string) LogzEntry

WithSource sets the source for the LogEntry.

func (*LogEntry) WithTraceID

func (le *LogEntry) WithTraceID(traceID string) LogzEntry

WithTraceID sets the trace ID for the LogEntry.

type LogFormat

type LogFormat string
const (
	JSON LogFormat = "json"
	TEXT LogFormat = "text"
	YAML LogFormat = "yaml"
	XML  LogFormat = "xml"
	RAW  LogFormat = "raw"
)

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 LogLevel

type LogLevel string

LogLevel represents the severity VLevel of a log entry.

const (
	DEBUG   LogLevel = "DEBUG"
	TRACE   LogLevel = "TRACE"
	NOTICE  LogLevel = "NOTICE"
	INFO    LogLevel = "INFO"
	SUCCESS LogLevel = "SUCCESS"
	WARN    LogLevel = "WARN"
	ERROR   LogLevel = "ERROR"
	FATAL   LogLevel = "FATAL"
	SILENT  LogLevel = "SILENT"
)

type LogMode

type LogMode string
const (
	ModeService    LogMode = "service"    // Indicates that the core is being used by a detached process
	ModeStandalone LogMode = "standalone" // Indicates that the core is being used locally (e.g., CLI)
)

type LogMultiWriter

type LogMultiWriter[T any] interface {
	Write(entry T) error
	AddWriter(w LogWriter[T])
	GetWriters() []LogWriter[T]
}

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 LogWriter

type LogWriter[T any] interface {
	Write(entry T) error
}

LogWriter defines the contract for writing 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) Disable

func (n *NotifierImpl) Disable()

Disable deactivates the notifier.

func (*NotifierImpl) Enable

func (n *NotifierImpl) Enable()

Enable activates the notifier.

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 TextFormatter

type TextFormatter struct{}

TextFormatter formats the log in plain text.

func (*TextFormatter) Format

func (f *TextFormatter) Format(entry LogzEntry) (string, error)

Format converts the log entry to a formatted string with colors and icons. Returns the formatted string and an error if formatting fails.

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.

Jump to

Keyboard shortcuts

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