Documentation
¶
Index ¶
- func Alert(name string, summary string, startsAt, endsAt time.Time, ...) error
- func ApplyOptions(options ...Option) error
- func Debug(message string, additionaValues map[string]any)
- func Error(message string, additionaValues map[string]any)
- func Info(message string, additionaValues map[string]any)
- func Init(level slog.Level, options ...Option) error
- func IsInitialized() bool
- func Log(level slog.Level, message string, additionaValues map[string]any)
- func MustParseLogLevel(s string) slog.Level
- func OnDebug(callback Callback)
- func OnErr(callback Callback)
- func OnInfo(callback Callback)
- func OnWarn(callback Callback)
- func ParseLogLevel(s string) (slog.Level, error)
- func SetLevel(level slog.Level)
- func Warn(message string, additionaValues map[string]any)
- func WithAlertManager(ctx context.Context, alertmanagerHost string, instance, service string, ...) error
- type AlertQueue
- type Callback
- type FileLoggerOption
- type LokiNotifier
- type LokiOption
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alert ¶
func Alert(name string, summary string, startsAt, endsAt time.Time, labels, annotations map[string]string, generatorURL string) error
NewAlert creates a new alert with the given parameters name is the name of the alert. If it is empty, an error will be returned. summary is a short description of the alert. If it is empty, an error will be returned. startsAt is the time when the alert starts, endsAt is the time when the alert ends. If they are omitted the current time will be used for both. If only one is omitted, the other will be set to it as well. If startsAt is after endsAt an error will be returned. labels are necessary information that will be sent to the alertmanager. The name, instance and baseLabels will be added to the annotations and overwrite existing keys. annotations are additional information that will be sent to the alertmanager. The summary will be added to the annotations. A common and recommended annotation is "summary" with a short description of the alert. generatorURL is the URL of the service that sends the alert. It is optional.
func ApplyOptions ¶
func IsInitialized ¶ added in v0.1.3
func IsInitialized() bool
func MustParseLogLevel ¶ added in v0.1.3
MustParseLogLevel is like ParseLogLevel but panics if the input is invalid
func ParseLogLevel ¶
ParseLogLevel parses a string into a slog.Level
func WithAlertManager ¶
func WithAlertManager(ctx context.Context, alertmanagerHost string, instance, service string, baseLabels map[string]string) error
WithAlertManager sets up the logger to send alerts to an alertmanager instance the context is used to check if the alertmanager instance is reachable AND for the runtime if the context is cancelled, the alertmanager will stop sending alerts alertmanagerHost is the host of the alertmanager instance baseLabels are the labels that will be added to all alerts, e.g. {"instance": "my-service"} returns an error if the alertmanager instance is not reachable
Types ¶
type AlertQueue ¶
type AlertQueue struct {
// contains filtered or unexported fields
}
type FileLoggerOption ¶
type FileLoggerOption func(*fileLogger)
type LokiNotifier ¶
type LokiNotifier struct {
// contains filtered or unexported fields
}
type LokiOption ¶
type LokiOption func(loki *LokiNotifier)
func WithBatchWait ¶
func WithBatchWait(duration time.Duration) LokiOption
func WithLevels ¶
func WithLevels(levels []slog.Level) LokiOption
type Option ¶
type Option func(*logger)
func WithLoki ¶
func WithLoki(ctx context.Context, lokiHost, server, job string, opts ...LokiOption) (Option, error)
WithLoki sets up the logger to send logs to a loki instance the context is used to check if the loki instance is reachable AND for the runtime if the context is cancelled, the loki will stop sending logs lokiHost is the host of the loki instance server is the name of the server that sends the logs job is the name of the job that sends the logs returns an error if the loki instance is not reachable or if the server or job is not set