observer/pkg/syslog/syslog.go
Natalia Goc ab5b70704d standardize commonly used attributes
Some commonly used at maal attributes have been encoded as consts with
convinience wrappers similar to those of semconv package from otel sdk.
Additionally some utils that can generate mutliple attributes were added.
2024-05-16 13:45:13 +02:00

85 lines
1.3 KiB
Go

package syslog
import (
"go.opentelemetry.io/otel/attribute"
)
type SyslogLevel uint8
type IntoSyslogLevel interface {
IntoSyslogLevel() SyslogLevel
}
const (
// System is unusable
EMERG SyslogLevel = iota
// Immediate action is needed
ALERT
// Critical condition exists
CRIT
// An error condition has occured
ERR
// A suspicious behaviour has been observed
WARNING
// Significant but acceptable event has occured
NOTICE
// Informational details
INFO
// Data useful during debugging
DEBUG
)
func (l SyslogLevel) String() string {
switch l {
case EMERG:
return "EMERG"
case ALERT:
return "ALERT"
case CRIT:
return "CRIT"
case ERR:
return "ERR"
case WARNING:
return "WARN"
case NOTICE:
return "NOTICE"
case INFO:
return "INFO"
case DEBUG:
return "DEBUG"
default:
return "CRIT"
}
}
func LevelFromString(level string) SyslogLevel {
switch level {
case "EMERG":
return EMERG
case "ALERT":
return ALERT
case "CRIT":
return CRIT
case "ERR":
return ERR
case "WARN":
return WARNING
case "NOTICE":
return NOTICE
case "INFO":
return INFO
case "DEBUG":
return DEBUG
default:
return CRIT
}
}
func (lvl SyslogLevel) IntoTraceAttribute() attribute.KeyValue {
return attribute.String("level", lvl.String())
}
func (lvl SyslogLevel) IntoSyslogLevel() SyslogLevel {
return lvl
}