/
aggregator.go
executable file
·65 lines (49 loc) · 1.58 KB
/
aggregator.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
package main
import (
"fmt"
"github.com/juju/loggo"
"github.com/spf13/viper"
"time"
"unicode/utf8"
)
var clogger = loggo.GetLogger("client")
type Consolidator struct {
conference string
user string
client string
message string
}
// DefaultFormatter provides a simple concatenation of all the components.
type ClientLogFormatter struct{}
// Format returns the parameters separated by spaces except for filename and
// line which are separated by a colon. The timestamp is shown to second
// resolution in UTC.
func (*ClientLogFormatter) Format(level loggo.Level, module, filename string, line int, timestamp time.Time, message string) string {
//ts := time.Now().Format(time.RFC3339)
ts := time.Now().Format("2006-01-02T15:04:05.999999Z07:00")
return fmt.Sprintf("%s %s", ts, message)
}
func WriteToLogFile(client string, meeting string, userid string, message string, remoteip string) (int64, error) {
var err error
var filesize int64 = -1
data := meeting + " " + userid + " " + message
//fmt.Println(data)
clogger.Infof(data)
return filesize, err
}
func CheckVars(client string, message string, meetingid string, userid string) bool {
valid := (len(message) != 0)
clientallowed := false
// Check if the sent client name is allowed to write to logs
for _, element := range viper.GetStringSlice("AllowedClients") {
clientallowed = clientallowed || (element == client)
}
if !clientallowed {
return false
}
values := [4]string{client, message, meetingid, userid}
for _, element := range values {
valid = valid && utf8.ValidString(element)
}
return valid
}