forked from jammer312/discording
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
86 lines (75 loc) · 1.47 KB
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"log"
"strings"
)
func log_line_runtime(in string) {
log.Println(in) // usual logging
log_line(in, "runtimes")
}
func log_line(in, ch string) {
if strings.HasSuffix(in, "connect: connection refused") || strings.HasSuffix(in, "i/o timeout") || strings.HasSuffix(in, "timed out") {
return //don't want to log it
}
if discord_up {
chans, ok := known_channels_s_t_id_m["generic"]
if !ok {
return
}
channels, ok := chans[ch]
if !ok || len(channels) < 1 {
return //no bound channels
}
for _, id := range channels {
send_message(id, in)
}
}
}
func logging_crash(ctx string) {
if r := recover(); r != nil {
log.Fatalln("ERRF: ["+ctx+"]:", r)
}
}
func logging_recover(ctx string) {
if r := recover(); r != nil {
log_line_runtime("ERR: [" + ctx + "]: " + fmt.Sprint(r))
}
}
func recovering_callback(callback func()) {
if r := recover(); r != nil {
callback()
}
}
func onerror(callback func()) {
if r := recover(); r != nil {
callback()
panic(r)
}
}
func logging_pass(ctx string) {
if r := recover(); r != nil {
log_line_runtime("ERR: [" + ctx + "]: " + fmt.Sprint(r))
panic(r)
}
}
func rise_error(app string) {
if r := recover(); r != nil {
panic(fmt.Sprintf("[%v]:%v", app, r))
}
}
func noerror(err error) {
if err != nil {
panic(err)
}
}
func assert(st bool, message string) {
if !st {
panic(message)
}
}
func maybeerror(err error) {
if err != nil {
log_line_runtime(fmt.Sprintf("MERR: %v", err))
}
}