-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
59 lines (46 loc) · 1.82 KB
/
logging.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
package main
import (
"fmt"
"log"
commonlib "github.com/kurtd5105/SENG-468-Common-Lib"
)
// buildLog builds a valid sendableLogCommand
func buildLog(logMessage string, logType int, logParameters commonlib.LogCommandParameter) []byte {
var logCommandID uint8
//log.Println(logMessage)
switch logType {
// Required fields: Timestamp, Server, TransactionNum, Command
// Optional fields: Username, StockSymbol, Filename, Funds, DebugMessage
case commonlib.DebugType:
logCommandID = uint8(commonlib.DebugType)
logParameters.DebugMessage = logMessage
// Required fields: Timestamp, Server, TransactionNum, Command
// Optional fields: Username, StockSymbol, Filename, Funds, ErrorMessage
case commonlib.ErrorEventType:
logCommandID = uint8(commonlib.ErrorEventType)
logParameters.ErrorMessage = logMessage
// Required fields: Timestamp, Server, TransactionNum, Command
// Optional fields: Username, StockSymbol, Filename, Funds
case commonlib.SystemEventType:
logCommandID = uint8(commonlib.SystemEventType)
// Required fields: Timestamp, Server, TransactionNum, Command
// Optional fields: Username, StockSymbol, Filename, Funds
case commonlib.UserCommandType:
logCommandID = uint8(commonlib.UserCommandType)
default:
log.Println("Web server not set up to handle this log type: " + string(logType))
}
sendableLogCommand := commonlib.GetSendableLogCommand(logCommandID, logParameters)
if len(sendableLogCommand) == 0 {
fmt.Println("GetSendableLogCommand returned a 0-length response")
}
return sendableLogCommand
}
// sendLog sends the given log as a message to the logging server
func sendLog(sendableLogCommand []byte) {
_, err := commonlib.SendCommand("POST", "application/json", state.loggingServerAddressAndPort, sendableLogCommand)
if err != nil {
log.Printf("Error: %s\n", err)
}
//log.Printf(replyBody)
}