-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
44 lines (33 loc) · 918 Bytes
/
log.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
package log
import (
"context"
"log"
"cloud.google.com/go/logging"
c "github.com/adanalife/tripbot/pkg/config/tripbot"
)
var client *logging.Client
var chatLogger *log.Logger
func init() {
var err error
// don't bother with this if we're in a test environment
if c.Conf.IsTesting() || c.Conf.IsDevelopment() {
return
}
ctx := context.Background()
// Sets your Google Cloud Platform project ID.
projectID := c.Conf.GoogleProjectID
// Creates a stackdriver logging client.
client, err = logging.NewClient(ctx, projectID)
if err != nil {
log.Fatalf("Failed to create stackdriver client: %v", err)
}
// defer client.Close()
// this will include all Twitch chat messages
chatLogger = client.Logger("twitch-chat").StandardLogger(logging.Info)
}
func ChatMsg(username, msg string) {
if c.Conf.IsTesting() || c.Conf.IsDevelopment() {
return
}
chatLogger.Printf("%s: %s", username, msg)
}