initial commit
This commit is contained in:
84
pkg/level/level.go
Normal file
84
pkg/level/level.go
Normal file
@ -0,0 +1,84 @@
|
||||
package level
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type SyslogLevel uint8
|
||||
|
||||
const (
|
||||
EMERG SyslogLevel = iota
|
||||
ALERT
|
||||
CRIT
|
||||
ERR
|
||||
WARNING
|
||||
NOTICE
|
||||
INFO
|
||||
DEBUG
|
||||
)
|
||||
|
||||
// Level Keyword Description
|
||||
// 0 emergencies System is unusable
|
||||
// 1 alerts Immediate action is needed
|
||||
// 2 critical Critical conditions exist
|
||||
// 3 errors Error conditions exist
|
||||
// 4 warnings Warning conditions exist
|
||||
// 5 notification Normal, but significant, conditions exist
|
||||
// 6 informational Informational messages
|
||||
// 7 debugging Debugging messages
|
||||
|
||||
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) SetAttribute(att ...attribute.KeyValue) trace.SpanStartEventOption {
|
||||
|
||||
att = append(att, attribute.Int("level", int(lvl)))
|
||||
|
||||
return trace.WithAttributes(
|
||||
att...,
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user