Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FilterHandle ¶
FilterHandle a filter handler
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.