-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
42 lines (34 loc) · 781 Bytes
/
log.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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/Zioyi/zocker/container"
log "github.com/sirupsen/logrus"
)
func LogContainer(containerName string, follow bool) {
containerLogDir := fmt.Sprintf(container.DefaultInfoLocation, containerName)
containerLogFilePath := containerLogDir + container.ContainerLogFile
var old []byte
for {
content, err := ioutil.ReadFile(containerLogFilePath)
if err != nil {
log.Errorf("read file %s error %v", containerLogFilePath, err)
return
}
if bytes.Compare(content, old) != 0 {
_, err := fmt.Fprint(os.Stdout, string(content))
if err != nil {
log.Errorf("fprint to stdout error %v", err)
return
}
}
if !follow {
break
}
old = content
time.Sleep(time.Second)
}
}