Documentation
¶
Index ¶
Constants ¶
const ( // DefaultExpiryKey is the key and index stored within // Mongo for log levels that have a duration. DefaultExpiryKey = "ttl-%s" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
Level string `json:"level" bson:"level"`
Time time.Time `json:"time" bson:"time"`
Message string `json:"message" bson:"message"`
Data map[string]any `json:"data" bson:"data"`
Error *Error `json:"error" bson:"error"`
Expiry map[string]time.Time `json:"expiry" bson:"expiry"`
}
Entry defines a singular entry sent to Mongo when a Logrus event is fired.
type Error ¶
type Error struct {
Code string `json:"code" bson:"code"`
Message string `json:"message" bson:"message"`
Operation string `json:"operation" bson:"op"`
Err string `json:"error" bson:"err"`
FileLine string `json:"file_line" bson:"file_line"`
}
Error defines a custom Error for log entries, detailing the file line, errors are returned as strings instead of the stdlib error.
type ExpirationLevels ¶
ExpirationLevels defines the map of log levels mapped to a duration a LevelIndex.
type FireHook ¶
type FireHook func(e Entry)
FireHook defines the function used for firing entry to a call back function.
type Options ¶
type Options struct {
// Collection is the Mongo collection to write to when
// a log is fired.
Collection *mongo.Collection
// FireHook is a hook function called just before an
// entry is logged to Mongo.
FireHook FireHook
// ExpirationLevels allows for the customisation of expiry
// time for each Logrus level by default entries do not expire.
// There may be instances where you want to keep Panics in
// the Mongo collection for longer than trace levels.
// For example:
/*
var levels = ExpirationLevels{
// Expire trace levels after 10 hours.
logrus.TraceLevel: time.Hour * 10
// Expire info levels after 24 hours.
logrus.InfoLevel:t ime.Hour * 24,
// Expire panic levels after 1 week.
logrus.InfoLevel:t ime.Hour * 24 * 6,
}
*/
ExpirationLevels ExpirationLevels
}
Options defines the configuration used for creating a new Mogrus hook.