Documentation
¶
Index ¶
- type Execer
- type Hook
- type Option
- func SetExec(exec Execer) Option
- func SetExtra(extra map[string]interface{}) Option
- func SetFilter(filter func(*logrus.Entry) *logrus.Entry) Option
- func SetLevels(levels ...logrus.Level) Option
- func SetMaxQueues(maxQueues int) Option
- func SetMaxWorkers(maxWorkers int) Option
- func SetOut(out io.Writer) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook to send logs to a mysql database
Example ¶
db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/myapp_test?charset=utf8")
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
tableName := "e_log"
mysqlHook := mysqlhook.New(
mysqlhook.SetExec(mysqlhook.NewExec(db, tableName)),
)
defer db.Exec(fmt.Sprintf("drop table %s", tableName))
log := logrus.New()
log.AddHook(mysqlHook)
log.WithField("foo", "bar").Info("foo test")
mysqlHook.Flush()
var message string
row := db.QueryRow(fmt.Sprintf("select message from %s", tableName))
err = row.Scan(&message)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(message)
Output: foo test
Click to show internal directories.
Click to hide internal directories.