-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstat.go
48 lines (40 loc) · 904 Bytes
/
stat.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
package main
import (
"io"
"os"
"strings"
"sync/atomic"
"github.com/as/log"
)
func init() {
log.Service = os.Getenv("SVC")
tags := strings.Split(os.Getenv("TAGS"), ",")
for i := 0; i+1 < len(tags); i += 2 {
key, val := tags[i], tags[i+1]
if key == "" || val == "" {
continue
}
log.Tags = log.Tags.Add(key, val)
}
for _, key := range strings.Split(os.Getenv("LOGENV"), ",") {
if val := os.Getenv(key); val != "" && key != "" {
log.Tags = log.Tags.Add(key, val)
}
}
log.Tags = log.Tags.Add("ver", Version)
}
var iostat = struct {
rx, tx int64
}{}
type rx struct{ io.Reader }
func (r rx) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
atomic.AddInt64(&iostat.rx, int64(n))
return n, err
}
type tx struct{ io.Writer }
func (w tx) Write(p []byte) (n int, err error) {
n, err = w.Writer.Write(p)
atomic.AddInt64(&iostat.tx, int64(n))
return n, err
}