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.
This commit is contained in:
84
pkg/syslog/syslog.go
Normal file
84
pkg/syslog/syslog.go
Normal file
@ -0,0 +1,84 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user