File tree 5 files changed +57
-19
lines changed
5 files changed +57
-19
lines changed Original file line number Diff line number Diff line change 1
1
.DS_Store
2
2
blimp.toml
3
- blimp
3
+ blimp
4
+ blimp.log
Original file line number Diff line number Diff line change @@ -10,15 +10,16 @@ require (
10
10
github.com/knadh/koanf/providers/file v0.1.0
11
11
github.com/knadh/koanf/providers/rawbytes v0.1.0
12
12
github.com/knadh/koanf/v2 v2.0.1
13
+ github.com/mmcdole/gofeed v1.2.1
13
14
github.com/prometheus-community/pro-bing v0.3.0
14
15
github.com/rivo/tview v0.0.0-20230826141931-7344139b5532
15
16
github.com/rs/zerolog v1.30.0
17
+ gopkg.in/natefinch/lumberjack.v2 v2.2.1
16
18
)
17
19
18
20
require (
19
21
github.com/PuerkitoBio/goquery v1.8.0 // indirect
20
22
github.com/andybalholm/cascadia v1.3.1 // indirect
21
- github.com/briandowns/openweathermap v0.19.0 // indirect
22
23
github.com/fsnotify/fsnotify v1.6.0 // indirect
23
24
github.com/gdamore/encoding v1.0.0 // indirect
24
25
github.com/google/uuid v1.3.0 // indirect
@@ -31,7 +32,6 @@ require (
31
32
github.com/mitchellh/copystructure v1.2.0 // indirect
32
33
github.com/mitchellh/mapstructure v1.5.0 // indirect
33
34
github.com/mitchellh/reflectwalk v1.0.2 // indirect
34
- github.com/mmcdole/gofeed v1.2.1 // indirect
35
35
github.com/mmcdole/goxpp v1.1.0 // indirect
36
36
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
37
37
github.com/modern-go/reflect2 v1.0.2 // indirect
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0g
2
2
github.com/PuerkitoBio/goquery v1.8.0 /go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI =
3
3
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c =
4
4
github.com/andybalholm/cascadia v1.3.1 /go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA =
5
- github.com/briandowns/openweathermap v0.19.0 h1:nkopLMEtZLxbZI1th6dOG6xkajpszofqf53r5K8mT9k =
6
- github.com/briandowns/openweathermap v0.19.0 /go.mod h1:0GLnknqicWxXnGi1IqoOaZIw+kIe5hkt+YM5WY3j8+0 =
7
5
github.com/coreos/go-systemd/v22 v22.5.0 /go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc =
8
6
github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
9
7
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
@@ -117,4 +115,6 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
117
115
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e /go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo =
118
116
golang.org/x/tools v0.1.12 /go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc =
119
117
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 /go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0 =
118
+ gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc =
119
+ gopkg.in/natefinch/lumberjack.v2 v2.2.1 /go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc =
120
120
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
Original file line number Diff line number Diff line change
1
+ package logging
2
+
3
+ import (
4
+ "io"
5
+ "os"
6
+
7
+ "github.com/merlinfuchs/blimp/internal/config"
8
+ "github.com/rs/zerolog"
9
+ "github.com/rs/zerolog/log"
10
+ "gopkg.in/natefinch/lumberjack.v2"
11
+ )
12
+
13
+ func InitLogger () {
14
+ logContext := log .With ()
15
+
16
+ logWriters := make ([]io.Writer , 0 )
17
+ logWriters = append (logWriters , & lumberjack.Logger {
18
+ Filename : config .K .String ("logging.filename" ),
19
+ MaxSize : config .K .Int ("logging.max_size" ),
20
+ MaxAge : config .K .Int ("logging.max_age" ),
21
+ MaxBackups : config .K .Int ("logging.max_backups" ),
22
+ })
23
+ if config .K .Bool ("debug" ) {
24
+ zerolog .SetGlobalLevel (zerolog .DebugLevel )
25
+ logWriters = append (logWriters , zerolog.ConsoleWriter {Out : os .Stdout })
26
+ } else {
27
+ zerolog .SetGlobalLevel (zerolog .InfoLevel )
28
+ }
29
+
30
+ writer := io .MultiWriter (logWriters ... )
31
+ log .Logger = logContext .Logger ().Output (writer )
32
+ }
Original file line number Diff line number Diff line change @@ -33,31 +33,36 @@ func New() *LatencyView {
33
33
}
34
34
35
35
func (l * LatencyView ) Start () {
36
- pinger , err := ping .NewPinger (config .K .String ("widgets.latency.target_host" ))
37
- if err != nil {
38
- log .Fatal ().Err (err ).Msgf ("Failed to create pinger, latency won't be displayed" )
39
- return
40
- }
36
+ var pinger * ping.Pinger
41
37
42
38
go func () {
43
39
<- l .stopped
44
- pinger .Stop ()
40
+ if pinger != nil {
41
+ pinger .Stop ()
42
+ }
45
43
}()
46
44
47
45
go func () {
48
- pinger .SetPrivileged (false )
49
- pinger .Interval = time .Duration (config .K .Int ("widgets.latency.update_interval" )) * time .Millisecond
50
-
51
- pinger .OnRecv = func (pkt * ping.Packet ) {
52
- newValue := float64 (pkt .Rtt .Microseconds ()) / 1000
53
- l .data = append (l .data [1 :], newValue )
54
- }
55
-
56
46
for {
57
47
select {
58
48
case <- l .stopped :
59
49
return
60
50
default :
51
+ var err error
52
+ pinger , err = ping .NewPinger (config .K .String ("widgets.latency.target_host" ))
53
+ if err != nil {
54
+ log .Error ().Err (err ).Msgf ("Failed to create pinger" )
55
+ return
56
+ }
57
+
58
+ pinger .SetPrivileged (false )
59
+ pinger .Interval = time .Duration (config .K .Int ("widgets.latency.update_interval" )) * time .Millisecond
60
+
61
+ pinger .OnRecv = func (pkt * ping.Packet ) {
62
+ newValue := float64 (pkt .Rtt .Microseconds ()) / 1000
63
+ l .data = append (l .data [1 :], newValue )
64
+ }
65
+
61
66
err = pinger .Run ()
62
67
if err != nil {
63
68
log .Error ().Err (err ).Msgf ("Failed to run pinger, latency won't be displayed" )
You can’t perform that action at this time.
0 commit comments