|
@@ -34,6 +34,9 @@ const (
|
|
|
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
|
|
|
// the format, a... portion this command follows that of fmt.Printf
|
|
|
// msgL : LogLevel of the message
|
|
@@ -42,18 +45,23 @@ const (
|
|
|
// a ... : comma seperated list of values to pass
|
|
|
func msglog(msgL, caller int, format string, a ...interface{}) {
|
|
|
|
|
|
- pc, file, line, _ := runtime.Caller(caller)
|
|
|
+ if Logger != nil {
|
|
|
+ Logger(msgL, caller, format, a)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ pc, file, line, _ := runtime.Caller(caller)
|
|
|
|
|
|
- files := strings.Split(file, "/")
|
|
|
- file = files[len(files)-1]
|
|
|
+ files := strings.Split(file, "/")
|
|
|
+ file = files[len(files)-1]
|
|
|
|
|
|
- name := runtime.FuncForPC(pc).Name()
|
|
|
- fns := strings.Split(name, ".")
|
|
|
- name = fns[len(fns)-1]
|
|
|
+ name := runtime.FuncForPC(pc).Name()
|
|
|
+ fns := strings.Split(name, ".")
|
|
|
+ name = fns[len(fns)-1]
|
|
|
|
|
|
- msg := fmt.Sprintf(format, a...)
|
|
|
+ msg := fmt.Sprintf(format, a...)
|
|
|
|
|
|
- log.Printf("[DG%d] %s:%d:%s() %s\n", msgL, file, line, name, msg)
|
|
|
+ log.Printf("[DG%d] %s:%d:%s() %s\n", msgL, file, line, name, msg)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// helper function that wraps msglog for the Session struct
|