Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecExtraItem ¶
ExecExtraItem extra item
func NewExecExtraItem ¶
func NewExecExtraItem(field, dbType string) *ExecExtraItem
NewExecExtraItem create extra item instance
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", dsn) if err != nil { fmt.Println(err) return } defer db.Close() tableName := "e_log" mysqlHook := mysqlhook.Default(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
func DefaultWithExtra ¶
func DefaultWithExtra(db *sql.DB, tableName string, extraItems []*ExecExtraItem, opts ...Option) *Hook
DefaultWithExtra create a default mysql hook with extra items
Click to show internal directories.
Click to hide internal directories.