lotus/journal/types.go

82 lines
2.3 KiB
Go
Raw Normal View History

2020-07-17 13:22:37 +00:00
package journal
2020-07-17 17:35:15 +00:00
import (
"time"
logging "github.com/ipfs/go-log"
2020-07-17 17:35:15 +00:00
)
2020-07-17 13:22:37 +00:00
var log = logging.Logger("journal")
2020-08-11 12:48:32 +00:00
var (
// DefaultDisabledEvents lists the journal events disabled by
// default, usually because they are considered noisy.
DefaultDisabledEvents = DisabledEvents{
EventType{System: "mpool", Event: "add"},
EventType{System: "mpool", Event: "remove"},
}
)
2020-07-20 13:45:17 +00:00
// DisabledEvents is the set of event types whose journaling is suppressed.
type DisabledEvents []EventType
2020-07-17 13:22:37 +00:00
// EventType represents the signature of an event.
type EventType struct {
System string
Event string
2020-07-17 17:35:15 +00:00
// enabled stores whether this event type is enabled.
enabled bool
// safe is a sentinel marker that's set to true if this EventType was
// constructed correctly (via Journal#RegisterEventType).
safe bool
}
func (et EventType) String() string {
return et.System + ":" + et.Event
}
2020-07-17 17:35:15 +00:00
// Enabled returns whether this event type is enabled in the journaling
// subsystem. Users are advised to check this before actually attempting to
// add a journal entry, as it helps bypass object construction for events that
// would be discarded anyway.
//
// All event types are enabled by default, and specific event types can only
// be disabled at Journal construction time.
func (et EventType) Enabled() bool {
2020-08-10 14:02:15 +00:00
return et.safe && et.enabled
}
2020-07-17 13:22:37 +00:00
// Journal represents an audit trail of system actions.
//
// Every entry is tagged with a timestamp, a system name, and an event name.
// The supplied data can be any type, as long as it is JSON serializable,
// including structs, map[string]interface{}, or primitive types.
//
// For cleanliness and type safety, we recommend to use typed events. See the
// *Evt struct types in this package for more info.
type Journal interface {
2020-08-26 15:09:37 +00:00
EventTypeRegistry
2020-07-17 13:22:37 +00:00
2020-08-26 15:09:37 +00:00
// RecordEvent records this event to the journal, if and only if the
// EventType is enabled. If so, it calls the supplier function to obtain
// the payload to record.
//
// Implementations MUST recover from panics raised by the supplier function.
RecordEvent(evtType EventType, supplier func() interface{})
2020-07-17 13:22:37 +00:00
// Close closes this journal for further writing.
Close() error
}
// Event represents a journal entry.
2020-07-17 13:22:37 +00:00
//
// See godocs on Journal for more information.
type Event struct {
2020-07-17 13:22:37 +00:00
EventType
Timestamp time.Time
Data interface{}
}