Initial working version
This commit is contained in:
parent
3bf8ccebf8
commit
5ea0bbfc87
11 changed files with 648 additions and 1 deletions
68
priority.go
Normal file
68
priority.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue