-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
64 lines (53 loc) · 1.16 KB
/
logger.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
package wlogger
import (
"fmt"
"log"
"path"
"runtime"
"codeberg.org/eviedelta/dwhook"
)
// Logger is a logger
type Logger struct {
Color int
Avatar string
Name string
Status string
Webhook *dwhook.Webhook
}
// Send sends a single string to the webhook
func (l *Logger) Send(s string, skip int) error {
log.Println(s)
if l.Webhook.ID == "" {
return nil
}
_, f, i, ok := runtime.Caller(1 + skip)
_, err := l.Webhook.Send(dwhook.Message{
Username: l.Name,
AvatarURL: l.Avatar,
Embeds: []dwhook.Embed{{
Title: l.Status,
Description: s,
Color: l.Color,
Footer: dwhook.EmbedFooter{
Text: func() string {
if ok {
return fmt.Sprintf("%v :%v", path.Base(f), i)
}
return "no source info"
}(),
},
}},
})
if err != nil {
log.Println(err)
}
return err
}
// Print prints a message to the webhook using the logic from fmt.Sprint()
func (l *Logger) Print(in ...interface{}) error {
return l.Send(fmt.Sprint(in...), 1)
}
// Printf prints a message to the webhook using the logic from fmt.Sprintf()
func (l *Logger) Printf(s string, in ...interface{}) error {
return l.Send(fmt.Sprintf(s, in...), 1)
}