forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
41 lines (33 loc) · 949 Bytes
/
util.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
package main
import (
"fmt"
"math/rand"
"time"
"github.com/StackVista/stackstate-agent/pkg/config"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// RandomString generates a random string of the given size
func RandomString(size int) string {
b := make([]byte, size)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
// TimeNowNano returns Unix time with nanosecond precision
func TimeNowNano() float64 {
return float64(time.Now().UnixNano()) / float64(time.Second)
}
// InitLogging inits default logger
func InitLogging(level string) error {
err := config.SetupLogger(config.LoggerName("test"), level, "", "", false, true, false)
if err != nil {
return fmt.Errorf("Unable to initiate logger: %s", err)
}
return nil
}
// SetHostname sets the hostname
func SetHostname(hostname string) {
mockConfig := config.Mock()
mockConfig.Set("hostname", hostname)
}