Add support for custom logging behaviour. (#465)
This commit is contained in:
parent
70c6c583e4
commit
d30b33abfa
2 changed files with 17 additions and 9 deletions
|
@ -21,7 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
|
// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
|
||||||
const VERSION = "0.17.0-dev"
|
const VERSION = "0.17.0"
|
||||||
|
|
||||||
// ErrMFA will be risen by New when the user has 2FA.
|
// ErrMFA will be risen by New when the user has 2FA.
|
||||||
var ErrMFA = errors.New("account has 2FA enabled")
|
var ErrMFA = errors.New("account has 2FA enabled")
|
||||||
|
|
24
logging.go
24
logging.go
|
@ -34,6 +34,9 @@ const (
|
||||||
LogDebug
|
LogDebug
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Logger can be used to replace the standard logging for discordgo
|
||||||
|
var Logger func(msgL, caller int, format string, a ...interface{})
|
||||||
|
|
||||||
// msglog provides package wide logging consistancy for discordgo
|
// msglog provides package wide logging consistancy for discordgo
|
||||||
// the format, a... portion this command follows that of fmt.Printf
|
// the format, a... portion this command follows that of fmt.Printf
|
||||||
// msgL : LogLevel of the message
|
// msgL : LogLevel of the message
|
||||||
|
@ -42,18 +45,23 @@ const (
|
||||||
// a ... : comma seperated list of values to pass
|
// a ... : comma seperated list of values to pass
|
||||||
func msglog(msgL, caller int, format string, a ...interface{}) {
|
func msglog(msgL, caller int, format string, a ...interface{}) {
|
||||||
|
|
||||||
pc, file, line, _ := runtime.Caller(caller)
|
if Logger != nil {
|
||||||
|
Logger(msgL, caller, format, a)
|
||||||
|
} else {
|
||||||
|
|
||||||
files := strings.Split(file, "/")
|
pc, file, line, _ := runtime.Caller(caller)
|
||||||
file = files[len(files)-1]
|
|
||||||
|
|
||||||
name := runtime.FuncForPC(pc).Name()
|
files := strings.Split(file, "/")
|
||||||
fns := strings.Split(name, ".")
|
file = files[len(files)-1]
|
||||||
name = fns[len(fns)-1]
|
|
||||||
|
|
||||||
msg := fmt.Sprintf(format, a...)
|
name := runtime.FuncForPC(pc).Name()
|
||||||
|
fns := strings.Split(name, ".")
|
||||||
|
name = fns[len(fns)-1]
|
||||||
|
|
||||||
log.Printf("[DG%d] %s:%d:%s() %s\n", msgL, file, line, name, msg)
|
msg := fmt.Sprintf(format, a...)
|
||||||
|
|
||||||
|
log.Printf("[DG%d] %s:%d:%s() %s\n", msgL, file, line, name, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function that wraps msglog for the Session struct
|
// helper function that wraps msglog for the Session struct
|
||||||
|
|
Loading…
Reference in a new issue