69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package journal
|
|
|
|
// Priority is the "level" or severity of the message.
|
|
type Priority int
|
|
|
|
const (
|
|
PriEmerg Priority = iota
|
|
PriAlert
|
|
PriCrit
|
|
PriErr
|
|
PriWarning
|
|
PriNotice
|
|
PriInfo
|
|
PriDebug
|
|
)
|
|
|
|
// String returns the same value as Keyword.
|
|
func (pri Priority) String() string {
|
|
return pri.Keyword()
|
|
}
|
|
|
|
// Keyword returns a keyword associated with the priority level. These should be
|
|
// recognisable to system operators.
|
|
func (pri Priority) Keyword() string {
|
|
switch pri {
|
|
case PriEmerg:
|
|
return "emerg"
|
|
case PriAlert:
|
|
return "alert"
|
|
case PriCrit:
|
|
return "crit"
|
|
case PriErr:
|
|
return "err"
|
|
case PriWarning:
|
|
return "warning"
|
|
case PriNotice:
|
|
return "notice"
|
|
case PriInfo:
|
|
return "info"
|
|
case PriDebug:
|
|
return "debug"
|
|
default:
|
|
return "?"
|
|
}
|
|
}
|
|
|
|
var priorityAttrKey = AttrKey{key: "PRIORITY"}
|
|
|
|
var priorityAttrMap = map[Priority]Attr{
|
|
PriEmerg: Attr{Key: priorityAttrKey, Value: []byte{'0'}},
|
|
PriAlert: Attr{Key: priorityAttrKey, Value: []byte{'1'}},
|
|
PriCrit: Attr{Key: priorityAttrKey, Value: []byte{'2'}},
|
|
PriErr: Attr{Key: priorityAttrKey, Value: []byte{'3'}},
|
|
PriWarning: Attr{Key: priorityAttrKey, Value: []byte{'4'}},
|
|
PriNotice: Attr{Key: priorityAttrKey, Value: []byte{'5'}},
|
|
PriInfo: Attr{Key: priorityAttrKey, Value: []byte{'6'}},
|
|
PriDebug: Attr{Key: priorityAttrKey, Value: []byte{'7'}},
|
|
}
|
|
|
|
var unknownPriorityAttr = Attr{Key: priorityAttrKey, Value: []byte{'6'}}
|
|
|
|
// Attr returns an attribute value ready to be used in a journal entry.
|
|
func (pri Priority) Attr() Attr {
|
|
if a, ok := priorityAttrMap[pri]; ok {
|
|
return a
|
|
}
|
|
return unknownPriorityAttr
|
|
}
|