Documentation
¶
Overview ¶
Package hooksyslog provides a robust and flexible logrus hook for writing log entries to syslog endpoints. It leverages a custom socket implementation for cross-platform network communication (TCP, UDP, Unix sockets), ensuring that syslog messages can be sent from any supported OS, including Windows. The package is designed for high-performance, asynchronous, and buffered logging with features like connection aggregation, automatic reconnection, and RFC 5424 compliance.
Overview ¶
The `hooksyslog` package integrates with `logrus` to redirect log messages to local or remote syslog servers. By abstracting network communication, it provides a unified logging mechanism across different operating systems. The implementation ensures non-blocking log operations by delegating buffering and asynchronous writing to an underlying aggregator component, which processes log entries in a dedicated background goroutine.
Design Philosophy ¶
The core principles guiding the design of this package are:
- True Cross-Platform Support: A single, consistent API for sending syslog messages over the network from any OS, including Windows, without relying on platform-specific logging APIs like Windows Event Log.
- Asynchronous Operation: Log calls from the application are non-blocking. The hook delegates the I/O operations to an internal aggregator that uses a buffered channel and a background worker, preventing performance bottlenecks.
- Connection Efficiency: A global connection aggregator manages and shares network connections to syslog endpoints. This reduces the overhead of creating new connections for each hook instance and minimizes resource usage.
- Robustness and Reliability: The underlying socket client implements automatic reconnection logic, ensuring that logging can resume seamlessly after transient network or service disruptions.
- Standard Compliance: Adheres to RFC 5424 for syslog message formatting, including priority, facility, and severity, enabling seamless integration with standard syslog collectors and analyzers.
Architecture ¶
The package's architecture is designed for modularity, connection sharing, and asynchronous processing.
┌───────────────────────────────────────────────────────────────────────────┐ │ Application (logrus) │ │ │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ HookSyslog Interface │ │ │ │ (logrus.Hook + Closer) │ │ │ └───────────────────────────────▲─────────────────────────────────────┘ │ │ │ │ │ │ Fire(entry *logrus.Entry) │ │ │ (non-blocking, writes to aggregator) │ │ │ │ │ ┌────────────────────────────────▼────────────────────────────────────┐ │ │ │ hks struct │ │ │ │ - Formatter and log level configuration │ │ │ │ - Reference to a shared, global connection aggregator (io.Writer) │ │ │ └─────────────────────────────────▲───────────────────────────────────┘ │ │ │ │ │ │ (Shared across multiple hooks) │ │ │ │ │ ┌─────────────────────────────────▼───────────────────────────────────┐ │ │ │ Global Connection Aggregator Map │ │ │ │ (Manages one aggregator per unique syslog endpoint) │ │ │ │ │ │ │ │ ┌───────────────────────────────────────────────────────────────┐ │ │ │ │ │ sysAgg (Connection Aggregator) │ │ │ │ │ │ - Reference counting for active hooks │ │ │ │ │ │ - Wraps an `iotagg.Aggregator` for buffering & async writes │ │ │ │ │ │ - Holds the underlying `libsck.Client` socket connection │ │ │ │ │ └──────────────────────────────▲────────────────────────────────┘ │ │ │ └─────────────────────────────────│───────────────────────────────────┘ │ │ │ │ │ │ (Delegated Async Processing) │ │ │ │ │ ┌─────────────────────────────────▼───────────────────────────────────┐ │ │ │ iotagg.Aggregator (from ioutils package) │ │ │ │ - Internal buffer (250 entries) and background goroutine │ │ │ │ - Pulls formatted messages and writes them to the socket │ │ │ │ - Manages write synchronization and error handling │ │ │ └─────────────────────────────────▲───────────────────────────────────┘ │ │ │ │ │ │ Write to network socket │ │ │ │ │ ┌─────────────────────────────────▼───────────────────────────────────┐ │ │ │ libsck.Client (from socket package) │ │ │ │ - Cross-platform TCP, UDP, and Unix socket client │ │ │ │ - Handles connection establishment and automatic reconnection │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────────────────────────┘
Platform-Specific Behavior ¶
The hook now provides consistent behavior across all platforms by using a network-first approach.
Unix/Linux (`sys_syslog.go`): If no network address is specified, the hook attempts to auto-discover the local syslog service by checking for standard Unix domain sockets (`/dev/log`, `/var/run/syslog`).
Windows (`sys_winlog.go`): Local syslog auto-discovery is not supported. An explicit network address (e.g., "udp", "localhost:514") must be provided in the configuration. The hook will send standard syslog messages to this endpoint.
Key Features ¶
Connection Aggregation: A global, thread-safe map manages a pool of aggregators, one for each unique syslog endpoint (protocol/address pair). This allows multiple `HookSyslog` instances to share a single underlying network connection, significantly reducing resource consumption. Reference counting ensures connections are closed only when no hooks are using them.
Delegated Asynchronous Writing: The hook itself is lightweight. The heavy lifting of buffering, asynchronous processing, and I/O is delegated to the `iotagg.Aggregator` component. This component runs a background goroutine to process a buffer of 250 log entries, ensuring `Fire()` calls are non-blocking.
Automatic Reconnection: The underlying `libsck.Client` automatically handles connection failures. If a write fails, it will attempt to reconnect to the syslog server before retrying the write, providing resilience against transient network issues.
RFC 5424 Formatting: The hook manually constructs RFC 5424-compliant syslog messages, including the priority value (calculated from facility and severity), timestamp, hostname, tag, and the log message itself.
Advantages ¶
- True Cross-Platform Operation: Eliminates dependencies on platform-specific APIs like `log/syslog` or Windows Event Log, providing a consistent syslog-over-network implementation everywhere.
- Resource Efficiency: Connection aggregation prevents the proliferation of sockets when multiple hooks point to the same destination.
- Non-blocking: Logrus calls return immediately, as I/O is handled by a background worker in the shared aggregator.
- Reliable: The combination of buffering and automatic reconnection minimizes log loss during temporary service unavailability.
Disadvantages ¶
- Latency: Asynchronous writes introduce a small delay between the log call and the actual transmission of the syslog message.
- Error Handling: Network errors are handled internally by the aggregator and printed to `os.Stderr`. They are not propagated back to the application's logging call.
- Global State: The use of a global map for connection aggregation introduces a shared state within the application, which can have implications for testing and resource management in complex scenarios.
Limitations ¶
- Buffer Overflow: If the rate of log production consistently exceeds the network write speed, the internal buffer (250 entries) can fill up, causing subsequent `Fire()` calls to block.
- No TLS: The current socket implementation does not support TLS-encrypted syslog connections.
Example Usage ¶
Refer to the `example_test.go` file for comprehensive examples, including:
- Configuration for remote syslog via TCP/UDP on any platform.
- Auto-discovery of local syslog on Unix-like systems.
- Graceful shutdown patterns using the `Close()` method on the hook.
Example (AccessLog) ¶
Example_accessLog demonstrates using access log mode for HTTP request logging. In this mode, behavior is reversed: the message IS written, fields are IGNORED.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "http-access",
EnableAccessLog: true, // Message-only mode
LogLevel: []string{"info"},
}
hook, err := logsys.New(opts, nil)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// IMPORTANT: In AccessLog mode, behavior is REVERSED!
// The message "GET /api/users - 200 OK - 45ms" IS output.
// The fields (method, path, status) are IGNORED.
logger.WithFields(logrus.Fields{
"method": "GET",
"path": "/api/users",
"status": 200,
}).Info("GET /api/users - 200 OK - 45ms")
time.Sleep(100 * time.Millisecond)
fmt.Println("Access log sent to syslog")
}
Output: Access log sent to syslog
Example (Basic) ¶
Example_basic demonstrates the simplest use case: creating a hook that writes to local syslog. Note: This example uses UDP which doesn't require an actual syslog daemon to be running.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
// Configure the hook with minimal settings
// In this example, we use UDP protocol which doesn't fail if no server is running
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514", // UDP doesn't fail without server
Tag: "myapp",
LogLevel: []string{"info", "warning", "error"},
}
// Create the hook
hook, err := logsys.New(opts, &logrus.TextFormatter{
DisableTimestamp: true, // Disable timestamp for predictable output
})
if err != nil {
fmt.Printf("Error creating hook: %v\n", err)
return
}
defer hook.Close()
// Start async writer goroutine
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
// Wait for hook to be ready
time.Sleep(100 * time.Millisecond)
// Create and configure logger
logger := logrus.New()
logger.SetOutput(os.Stderr) // Use Stderr to separate from syslog output
logger.AddHook(hook)
// IMPORTANT: The message parameter "ignored" is NOT used by the hook in standard mode.
// Only the fields (here "msg") are written to syslog.
// Exception: In AccessLog mode, only the message is used and fields are ignored.
logger.WithField("msg", "Application started successfully").Info("ignored")
// Wait for async write
time.Sleep(100 * time.Millisecond)
fmt.Println("Log sent to syslog")
}
Output: Log sent to syslog
Example (FieldFiltering) ¶
Example_fieldFiltering demonstrates filtering specific fields from output.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
// Configure to filter out stack and timestamp
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "clean-app",
DisableStack: true, // Remove stack fields
DisableTimestamp: true, // Remove time fields
EnableTrace: false, // Remove caller/file/line fields
LogLevel: []string{"info"},
}
hook, err := logsys.New(opts, &logrus.TextFormatter{
DisableTimestamp: true,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// IMPORTANT: message "ignored" is NOT used, only fields
logger.WithFields(logrus.Fields{
"msg": "Filtered log entry",
"stack": "will be filtered out",
"caller": "will be filtered out",
"user": "john",
"action": "login",
}).Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Filtered log sent to syslog")
}
Output: Filtered log sent to syslog
Example (LevelFiltering) ¶
Example_levelFiltering demonstrates filtering logs by level.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "filtered-app",
LogLevel: []string{"error", "fatal"}, // Only errors and above
}
hook, err := logsys.New(opts, &logrus.TextFormatter{
DisableTimestamp: true,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// This will be written (error level)
// Note: message "ignored" is NOT used, only the field "msg"
logger.WithField("msg", "Database connection failed").Error("ignored")
// This won't be written to syslog (wrong level)
logger.WithField("msg", "Request completed").Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Filtered logs sent to syslog")
}
Output: Filtered logs sent to syslog
Example (MultipleHooks) ¶
Example_multipleHooks demonstrates using multiple hooks for different destinations.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
// Hook for errors only
errorOpts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "errors",
LogLevel: []string{"error", "fatal"},
}
errorHook, err := logsys.New(errorOpts, nil)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer errorHook.Close()
// Hook for all levels
allOpts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "all-logs",
}
allHook, err := logsys.New(allOpts, nil)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer allHook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go errorHook.Run(ctx)
go allHook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(errorHook)
logger.AddHook(allHook)
// This goes to both hooks
logger.WithField("msg", "Critical error occurred").Error("ignored")
// This goes only to allHook
logger.WithField("msg", "Normal operation").Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Logs sent to multiple syslog destinations")
}
Output: Logs sent to multiple syslog destinations
Example (RemoteUdp) ¶
Example_remoteUdp demonstrates sending logs to a remote syslog server via UDP.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514", // Remote syslog server
Tag: "remote-app",
Facility: "LOCAL0", // Use LOCAL0 facility
LogLevel: []string{"info", "error"},
}
hook, err := logsys.New(opts, &logrus.JSONFormatter{})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// IMPORTANT: Use fields, not message parameter
logger.WithFields(logrus.Fields{
"msg": "Remote logging test",
"service": "api",
"instance": "prod-1",
}).Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Log sent to remote syslog via UDP")
}
Output: Log sent to remote syslog via UDP
Example (StructuredLogging) ¶
Example_structuredLogging demonstrates structured logging with JSON formatter.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "structured-app",
LogLevel: []string{"info"},
}
hook, err := logsys.New(opts, &logrus.JSONFormatter{})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// IMPORTANT: message parameter is NOT used, only fields
logger.WithFields(logrus.Fields{
"user_id": 12345,
"action": "purchase",
"amount": 99.99,
"currency": "USD",
"msg": "Purchase completed",
"request_id": "abc-123-def",
}).Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Structured log sent to syslog")
}
Output: Structured log sent to syslog
Example (TraceEnabled) ¶
Example_traceEnabled demonstrates enabling trace information in logs.
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
logcfg "github.com/nabbar/golib/logger/config"
logsys "github.com/nabbar/golib/logger/hooksyslog"
libptc "github.com/nabbar/golib/network/protocol"
)
func main() {
// reset between examples
defer logsys.ResetOpenSyslog()
opts := logcfg.OptionsSyslog{
Network: libptc.NetworkUDP.Code(),
Host: "localhost:514",
Tag: "trace-app",
EnableTrace: true, // Include caller/file/line information
LogLevel: []string{"info"},
}
hook, err := logsys.New(opts, &logrus.TextFormatter{
DisableTimestamp: true,
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer hook.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go hook.Run(ctx)
time.Sleep(100 * time.Millisecond)
logger := logrus.New()
logger.SetOutput(os.Stderr)
logger.AddHook(hook)
// IMPORTANT: message "ignored" is NOT used, only fields
logger.WithFields(logrus.Fields{
"msg": "Log with trace info",
"caller": "main.processRequest",
"file": "main.go",
"line": 42,
}).Info("ignored")
time.Sleep(100 * time.Millisecond)
fmt.Println("Log with trace sent to syslog")
}
Output: Log with trace sent to syslog
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PriorityCalc ¶ added in v1.19.1
PriorityCalc calculates the syslog Priority value (PRIVAL) as defined in RFC 5424. PRIVAL = (Facility * 8) + Severity. This value is placed at the beginning of a syslog message in angle brackets (e.g., <165>).
func ResetOpenSyslog ¶ added in v1.19.1
func ResetOpenSyslog()
ResetOpenSyslog closes all active syslog connections and clears the aggregator map. This is primarily useful for testing or for scenarios requiring a full reset of the logging infrastructure.
Types ¶
type Facility ¶ added in v1.19.1
type Facility uint8
Facility represents the facility code of a syslog message according to RFC 5424. The facility indicates the type of program or system component generating the message.
Facilities are typically used for filtering and routing syslog messages:
- KERN: Kernel messages
- USER: User-level messages (default for applications)
- MAIL: Mail system
- DAEMON: System daemons
- AUTH: Security/authorization messages
- SYSLOG: Messages generated internally by syslogd
- LPR: Line printer subsystem
- NEWS: Network news subsystem
- UUCP: UUCP subsystem
- CRON: Clock daemon
- AUTHPRIV: Security/authorization messages (private)
- FTP: FTP daemon
- LOCAL0-LOCAL7: Reserved for local use (application-specific)
const ( FacilityKern Facility = iota // Kernel messages FacilityUser // User-level messages FacilityMail // Mail system FacilityDaemon // System daemons FacilityAuth // Security/authorization messages FacilitySyslog // Messages generated internally by syslogd FacilityLpr // Line printer subsystem FacilityNews // Network news subsystem FacilityUucp // UUCP subsystem FacilityCron // Clock daemon FacilityAuthPriv // Security/authorization messages (private) FacilityFTP // FTP daemon FacilityLocal0 // Local use 0 FacilityLocal1 // Local use 1 FacilityLocal2 // Local use 2 FacilityLocal3 // Local use 3 FacilityLocal4 // Local use 4 FacilityLocal5 // Local use 5 FacilityLocal6 // Local use 6 FacilityLocal7 // Local use 7 )
func MakeFacility ¶
MakeFacility converts a facility string to a Facility value. The conversion is case-insensitive. Returns 0 if the string doesn't match any known facility.
type HookSyslog ¶
HookSyslog is a logrus hook that writes log entries to a syslog endpoint. It extends the standard logrus.Hook interface with additional methods for lifecycle management.
The hook operates asynchronously by delegating the actual writing to a shared, buffered aggregator. This prevents blocking the main logging goroutine.
Platform support:
- Unix/Linux: Supports local syslog (via Unix domain sockets) and remote syslog (TCP/UDP).
- Windows: Supports remote syslog (TCP/UDP). Local syslog is not supported.
Thread safety:
- Fire() is safe for concurrent calls.
- Close() should be called once during shutdown to release resources.
Example:
opts := logcfg.OptionsSyslog{
Network: "udp",
Host: "syslog.example.com:514",
Tag: "myapp",
LogLevel: []string{"info", "error"},
}
hook, _ := New(opts, &logrus.JSONFormatter{})
logger.AddHook(hook)
defer hook.Close()
func New ¶
func New(opt logcfg.OptionsSyslog, format logrus.Formatter) (HookSyslog, error)
New creates a new HookSyslog instance with the specified configuration.
This function initializes the hook and establishes a connection to the syslog endpoint via a shared aggregator. If an aggregator for the specified endpoint already exists, it is reused, and its reference count is incremented.
The background writer goroutine is managed automatically by the aggregator, so there is no need to manually start a run loop.
Parameters:
- opt: Configuration options including network, host, tag, facility, and filters.
- format: Logrus formatter for log entries (nil for default text format).
Configuration:
- opt.Network: Protocol ("tcp", "udp", "unixgram", "unix"). Empty string implies local auto-discovery (Unix only).
- opt.Host: Syslog server address ("host:port" for TCP/UDP, "/dev/log" for Unix).
- opt.Tag: Syslog tag/application name (appears in syslog output). Defaults to process name.
- opt.Facility: Syslog facility ("LOCAL0"-"LOCAL7", "USER", "DAEMON", etc.).
- opt.LogLevel: Filter log levels (empty = all levels).
- opt.DisableStack: Remove "stack" field from output.
- opt.DisableTimestamp: Remove "time" field from output.
- opt.EnableTrace: Include "caller", "file", "line" fields.
- opt.EnableAccessLog: Write entry.Message instead of formatted fields.
Returns:
- HookSyslog: Configured hook ready to use.
- error: Non-nil if unable to initialize the connection aggregator.
Example:
opts := logcfg.OptionsSyslog{
Network: "tcp",
Host: "192.168.1.50:514",
Tag: "myapp",
Facility: "USER",
LogLevel: []string{"info", "warning", "error"},
}
hook, err := New(opts, &logrus.JSONFormatter{})
if err != nil {
return nil, fmt.Errorf("failed to create syslog hook: %w", err)
}
logger.AddHook(hook)
type Severity ¶ added in v1.19.1
type Severity uint8
Severity represents the severity level of a syslog message according to RFC 5424. Lower numerical values indicate higher severity.
The severity levels map to logrus levels as follows:
- Emergency (0): System is unusable
- Alert (1): Action must be taken immediately → logrus.PanicLevel
- Critical (2): Critical conditions → logrus.FatalLevel
- Error (3): Error conditions → logrus.ErrorLevel
- Warning (4): Warning conditions → logrus.WarnLevel
- Notice (5): Normal but significant condition
- Informational (6): Informational messages → logrus.InfoLevel
- Debug (7): Debug-level messages → logrus.DebugLevel
const ( SeverityEmerg Severity = iota // System is unusable SeverityAlert // Action must be taken immediately SeverityCrit // Critical conditions SeverityErr // Error conditions SeverityWarning // Warning conditions SeverityNotice // Normal but significant condition SeverityInfo // Informational messages SeverityDebug // Debug-level messages )
func ListSeverity ¶ added in v1.19.1
func ListSeverity() []Severity
ListSeverity returns a slice containing all defined Severity levels in order from Emergency (0) to Debug (7).
func MakeSeverity ¶
MakeSeverity converts a severity string to a Severity value. The conversion is case-insensitive. Returns 0 if the string doesn't match any known severity.