123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package discordgo
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "log"
- "runtime"
- "strings"
- )
- const (
-
-
-
- LogError int = iota
-
-
- LogWarning
-
- LogInformational
-
- LogDebug
- )
- func msglog(cfgL, msgL int, format string, a ...interface{}) {
- if msgL > cfgL {
- return
- }
- pc, file, line, _ := runtime.Caller(1)
- 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("%s:%d:%s %s\n", file, line, name, msg)
- }
- func (s *Session) log(msgL int, format string, a ...interface{}) {
- if s.Debug {
- s.LogLevel = LogDebug
- }
- msglog(s.LogLevel, msgL, format, a...)
- }
- func (v *VoiceConnection) log(msgL int, format string, a ...interface{}) {
- if v.Debug {
- v.LogLevel = LogDebug
- }
- msglog(v.LogLevel, msgL, format, a...)
- }
- func printEvent(e *Event) {
- log.Println(fmt.Sprintf("Event. Type: %s, State: %d Operation: %d Direction: %d", e.Type, e.State, e.Operation, e.Direction))
- printJSON(e.RawData)
- }
- 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()))
- }
|