-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatlog.go
34 lines (27 loc) · 910 Bytes
/
chatlog.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
package main
import (
"io"
"os"
"regexp"
"time"
)
var invalidCharsInFilenamesRegex = regexp.MustCompile("[/<>:\"\\|?*]")
func NewChatLogger(filename string) func(string) {
if !clientCfg.ChatLogsEnabled {
return func(string) {}
}
filename = invalidCharsInFilenamesRegex.ReplaceAllString(filename, "_") + ".log"
logger := func(message string) {
f, err := os.OpenFile(CHATLOG_DIR+filename, os.O_CREATE|os.O_APPEND, os.ModePerm)
checkErr(err)
defer f.Close()
io.WriteString(f, message+"\n")
}
// NOTE(tso): even if it's never called, the creation of a chat logger
// means that logging began, right?
// this might get annoying when joining channels by accident
// and having a log file written
// -tso 7/11/2018 7:30:49 PM
logger(time.Now().Format("-----------------------Mon Jan 2 15:04:05 -0700 MST 2006-----------------------"))
return logger
}