123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package discordgo
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "log"
- "runtime"
- "strings"
- )
- const (
-
-
- LogError int = iota
-
-
- LogWarning
-
-
- LogInformational
-
-
-
- LogDebug
- )
- func msglog(msgL, caller int, format string, a ...interface{}) {
- 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 s.Debug {
- s.LogLevel = LogDebug
- }
- if msgL > s.LogLevel {
- return
- }
- msglog(msgL, 2, format, a...)
- }
- func (v *VoiceConnection) log(msgL int, format string, a ...interface{}) {
- if v.Debug {
- v.LogLevel = LogDebug
- }
- if msgL > v.LogLevel {
- return
- }
- msglog(msgL, 2, format, a...)
- }
- func printJSON(body []byte) {
- var prettyJSON bytes.Buffer
- error := json.Indent(&prettyJSON, body, "", "\t")
- if error != nil {
- log.Print("JSON parse error: ", error)
- }
- log.Println(string(prettyJSON.Bytes()))
- }
|