This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper.go
75 lines (65 loc) · 1.65 KB
/
helper.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
66
67
68
69
70
71
72
73
74
75
/* Apache v2 license
* Copyright (C) <2019> Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"encoding/base64"
"encoding/binary"
"fmt"
golog "log"
"math"
"strings"
"github.com/intel/rsp-sw-toolkit-im-suite-utilities/go-metrics"
log "github.com/sirupsen/logrus"
)
func errorHandler(message string, err error, errorGauge *metrics.Gauge) {
if err != nil {
if errorGauge != nil {
(*errorGauge).Update(1)
}
log.WithFields(log.Fields{
"Method": "main",
"Error": fmt.Sprintf("%+v", err),
}).Error(message)
}
}
func fatalErrorHandler(message string, err error, errorGauge *metrics.Gauge) {
if err != nil {
if errorGauge != nil {
(*errorGauge).Update(1)
}
log.WithFields(log.Fields{
"Method": "main",
"Error": fmt.Sprintf("%+v", err),
}).Fatal(message)
}
}
func setLoggingLevel(loggingLevel string) {
switch strings.ToLower(loggingLevel) {
case "error":
log.SetLevel(log.ErrorLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "debug":
log.SetLevel(log.DebugLevel)
case "trace":
log.SetLevel(log.TraceLevel)
default:
log.SetLevel(log.InfoLevel)
}
// Not using filtered func (Info, etc ) so that message is always logged
golog.Printf("Logging level set to %s\n", loggingLevel)
}
func base64TemperatureToFloat32(base64Value string) float32 {
decodedValue, err := base64.StdEncoding.DecodeString(base64Value)
if err != nil {
log.Errorf("Unable to decode temperature base64 value: %s", err)
}
tempValue := math.Float32frombits(binary.BigEndian.Uint32(decodedValue))
log.Debugf("Setting temperature %f", tempValue)
return tempValue
}