1
1
package main
2
2
3
3
import (
4
- "github.com/Abramovic/logrus_influxdb"
5
4
log "github.com/Sirupsen/logrus"
6
5
"github.com/codegangsta/negroni"
7
6
"github.com/elazarl/goproxy"
8
- _ "github.com/influxdb/influxdb/client/v2"
9
7
"github.com/meatballhat/negroni-logrus"
10
8
11
- "errors"
12
9
"flag"
13
10
"fmt"
14
11
"net/http"
15
12
"os"
16
13
"regexp"
17
- "time"
18
14
)
19
15
20
16
const DefaultPort = ":8500"
@@ -29,15 +25,6 @@ func main() {
29
25
// getting settings
30
26
initSettings ()
31
27
32
- // adding influxdb hook
33
- err := addInfluxLoggingHook ()
34
-
35
- if err != nil {
36
- log .WithFields (log.Fields {
37
- "Error" : err .Error (),
38
- }).Error ("Failed to add InfluxDB hook" )
39
- }
40
-
41
28
// overriding default settings
42
29
AppConfig .recordState = * record
43
30
@@ -145,47 +132,3 @@ func (d *DBClient) startAdminInterface() {
145
132
146
133
n .Run (AppConfig .adminInterface )
147
134
}
148
-
149
- func addInfluxLoggingHook () error {
150
- // checking whether app should send logs to influxdb
151
- influxdbAddress := os .Getenv ("InfluxAddress" )
152
-
153
- if influxdbAddress != "" {
154
-
155
- // getting default events database
156
- influxDatabaseName := os .Getenv ("InfluxDBName" )
157
- if influxDatabaseName == "" {
158
- influxDatabaseName = "events"
159
- }
160
-
161
- var maxRetries = 10
162
- var errMaxRetriesReached = errors .New ("exceeded retry limit" )
163
- var err error
164
-
165
- attempt := 1
166
- for {
167
- hook , err := logrus_influxdb .NewInfluxDBHook (influxdbAddress , influxDatabaseName , nil )
168
- log .Info ("Hook created, next step - adding to logrus" )
169
- if err == nil {
170
- log .AddHook (hook )
171
- log .Info ("Hook to InfluxDB added successfuly" )
172
- break
173
- }
174
- attempt ++
175
- log .Warn ("Failed to connect to InfluxDB, maybe it is not running yet? Waiting..." )
176
- time .Sleep (5 * time .Second )
177
- if attempt > maxRetries {
178
- log .WithFields (log.Fields {
179
- "Error" : err .Error (),
180
- "InfluxDB" : influxdbAddress ,
181
- "InfluxDatabaseName" : influxDatabaseName ,
182
- }).Error ("Unable to add InfluxDB hook" )
183
- return errMaxRetriesReached
184
- }
185
- }
186
- return err
187
-
188
- } else {
189
- return nil
190
- }
191
- }
0 commit comments