Documentation ¶
Index ¶
Constants ¶
const ( // DiscordMaxMessageLen max discord message length. DiscordMaxMessageLen = 2000 // DefaultTimeLayout default time layout to Formatter implementations. DefaultTimeLayout = "2006-01-02 15:04:05" )
const ( ColorGreen = 0x0008000 ColorYellow = 0xffaa00 ColorRed = 0xff0000 )
Colors for log levels.
const (
// EmbedFormatterCode formatter code to identify from config.
EmbedFormatterCode = "embed"
)
const JsonFormatterCode = "json"
JsonFormatterCode formatter code to identify from config.
const TextFormatterCode = "text"
TextFormatterCode formatter code to identify from config.
Variables ¶
var ( // ErrEmptyToken is returned when discord bot token is empty with enabled hook. ErrEmptyToken = errors.New("discord bot token is empty") // ErrEmptyChannelID is returned when discord channel id is empty with enabled hook. ErrEmptyChannelID = errors.New("discord channel id is empty") // ErrMessageTooLong is returned when message that has been sent to discord longer // than 2000 characters. ErrMessageTooLong = errors.New("discord message too long") )
var DefaultEmbedFormatter = &EmbedFormatter{ Inline: true, TimestampFormat: DefaultTimeLayout, }
DefaultEmbedFormatter used as default EmbedFormatter.
var DefaultJSONFormatter = &JSONFormatter{ JSONFormatter: logrus.JSONFormatter{ TimestampFormat: DefaultTimeLayout, }, Quoted: true, }
DefaultJSONFormatter used as default JSONFormatter.
var DefaultTextFormatter = &TextFormatter{ TextFormatter: logrus.TextFormatter{ TimestampFormat: DefaultTimeLayout, QuoteEmptyFields: true, }, Quoted: true, }
DefaultTextFormatter used as default TextFormatter.
Functions ¶
func LevelColor ¶
LevelColor returns the respective color for the logrus level.
Types ¶
type Config ¶
type Config struct { // Disabled can disable hook form configuration file. Disabled bool `json:"disabled" yaml:"disabled"` // Token is bot token from discord developers applications. Token string `json:"token" yaml:"token"` // ChannelID is id of discord channel to log hooks. ChannelID string `json:"channel_id" yaml:"channel_id"` // Format specifies formatter to discord message. // Supported formats: text, json, embed. Format string `json:"format" yaml:"format"` // MinLevel is the minimum priority level to enable logging. MinLevel string `json:"min_level" yaml:"min_level"` // Levels is a list of levels to enable logging. Intersects with MinLevel. Levels []string `json:"levels" yaml:"levels"` }
Config handles discord bot connection configuration and logrus levels.
func NewDefaultConfig ¶
NewDefaultConfig returns default configuration for hook.
type EmbedFormatter ¶
type EmbedFormatter struct { // Inline causes fields to be displayed one per line // as opposed to being inline. Inline bool // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string // DisableTimestamp allows disabling automatic timestamps in output. DisableTimestamp bool // The fields are sorted by default for a consistent output. For applications // that log extremely frequently and don't use the JSON formatter this may not // be desired. DisableSorting bool // The keys sorting function, when uninitialized it uses sort.Strings. SortingFunc func([]string) }
EmbedFormatter formats logs into parsable json.
func (*EmbedFormatter) Embed ¶
func (f *EmbedFormatter) Embed(entry *logrus.Entry) *discordgo.MessageEmbed
Embed creates discord embed message from logrus entry.
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook implements logrus.Hook and delivers logs to discord channel.
type JSONFormatter ¶
type JSONFormatter struct { logrus.JSONFormatter // Quoted will quote string to discord tag json. Quoted bool }
JSONFormatter formats logs into parsable json.
type Option ¶
type Option func(client *Hook)
Options can be used to a create a customized connection.
func SetFormatter ¶
SetFormatter sets custom formatter to Hook.
func SetSession ¶
SetSession sets discordgo session to Hook.
type TextFormatter ¶
type TextFormatter struct { logrus.TextFormatter // Quoted will quote string to discord tag text. Quoted bool }
TextFormatter formats logs into text.