This repository has been archived by the owner on Feb 5, 2023. It is now read-only.
forked from abramovic/logrus_influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
75 lines (67 loc) · 1.91 KB
/
config.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
package logrus_influxdb
import (
"time"
)
// Config handles InfluxDB configuration, Logrus tags and batching inserts to InfluxDB
type Config struct {
// InfluxDB Configurations
Host string `json:"influxdb_host"`
Port int `json:"influxdb_port"`
Timeout time.Duration `json:"influxdb_timeout"`
Bucket string `json:"influxdb_bucket"`
Organization string `json:"influx_organization"`
Token string `json:"influx_token"`
UseHTTPS bool `json:"influxdb_https"`
Precision time.Duration `json:"influxdb_precision"`
// Enable syslog format for chronograf logviewer usage
Syslog bool `json:"syslog_enabled"`
Facility string `json:"syslog_facility"`
FacilityCode int `json:"syslog_facility_code"`
AppName string `json:"syslog_app_name"`
Version string `json:"syslog_app_version"`
// Minimum level for push
MinLevel string `json:"syslog_min_level"`
// Logrus tags
Tags []string `json:"logrus_tags"`
// Defaults
Measurement string `json:"measurement"`
// Batching
BatchIntervalMs uint `json:"batch_interval"` // Defaults to 5s.
BatchCount uint `json:"batch_count"` // Defaults to 200.
}
// Set the default configurations
func (c *Config) defaults() {
if c.Host == "" {
c.Host = defaultHost
}
if c.Port == 0 {
c.Port = defaultPort
}
if c.Timeout == 0 {
c.Timeout = 100 * time.Millisecond
}
if c.Bucket == "" {
c.Bucket = defaultBucket
}
//if c.Username == "" {
// c.Username = os.Getenv("INFLUX_USER")
//}
//if c.Password == "" {
// c.Password = os.Getenv("INFLUX_PWD")
//}
if c.Precision == time.Duration(0) {
c.Precision = defaultPrecision
}
if c.Tags == nil {
c.Tags = []string{}
}
if c.Measurement == "" {
c.Measurement = defaultMeasurement
}
if c.BatchCount <= 0 {
c.BatchCount = defaultBatchCount
}
if c.BatchIntervalMs <= 0 {
c.BatchIntervalMs = defaultBatchIntervalMs
}
}