-
Notifications
You must be signed in to change notification settings - Fork 10
/
bulk.go
42 lines (37 loc) · 1.09 KB
/
bulk.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
package coralogix
import (
"encoding/json"
"os"
)
// Bulk describe logs batch format for Coralogix API
type Bulk struct {
PrivateKey string `json:"privateKey"` // Coralogix private key
ApplicationName string `json:"applicationName"` // Your application name
SubsystemName string `json:"subsystemName"` // Subsystem name of your application
ComputerName string `json:"computerName"` // Current machine hostname
LogEntries []Log `json:"logEntries"` // Log records list
}
// NewBulk initialize new logs bulk
func NewBulk(Credentials Credentials) *Bulk {
Hostname, _ := os.Hostname()
return &Bulk{
Credentials.PrivateKey,
Credentials.ApplicationName,
Credentials.SubsystemName,
Hostname,
[]Log{},
}
}
// AddRecord add log record to the logs bulk
func (bulk *Bulk) AddRecord(Record Log) {
bulk.LogEntries = append(bulk.LogEntries, Record)
}
// ToJSON convert logs bulk to JSON format
func (bulk *Bulk) ToJSON() []byte {
data, err := json.Marshal(bulk)
if err != nil {
DebugLogger.Println("Can't convert logs bulk to JSON: ", err)
return nil
}
return data
}