123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package discordgo
- import (
- "fmt"
- "log"
- "runtime"
- "strings"
- )
- const (
-
-
- LogError int = iota
-
-
- LogWarning
-
- LogInformational
-
-
- LogDebug
- )
- var Logger func(msgL, caller int, format string, a ...interface{})
- // msglog provides package wide logging consistency for discordgo
- // the format, a... portion this command follows that of fmt.Printf
- // msgL : LogLevel of the message
- // caller : 1 + the number of callers away from the message source
- // format : Printf style message format
- // a ... : comma separated list of values to pass
- func msglog(msgL, caller int, format string, a ...interface{}) {
- if Logger != nil {
- Logger(msgL, caller, format, a...)
- } else {
- pc, file, line, _ := runtime.Caller(caller)
- files := strings.Split(file, "/")
- file = files[len(files)-1]
- name := runtime.FuncForPC(pc).Name()
- fns := strings.Split(name, ".")
- name = fns[len(fns)-1]
- msg := fmt.Sprintf(format, a...)
- log.Printf("[DG%d] %s:%d:%s() %s\n", msgL, file, line, name, msg)
- }
- }
- func (s *Session) log(msgL int, format string, a ...interface{}) {
- if msgL > s.LogLevel {
- return
- }
- msglog(msgL, 2, format, a...)
- }
- func (v *VoiceConnection) log(msgL int, format string, a ...interface{}) {
- if msgL > v.LogLevel {
- return
- }
- msglog(msgL, 2, format, a...)
- }
|