-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.go
More file actions
41 lines (33 loc) · 745 Bytes
/
Copy pathlog.go
File metadata and controls
41 lines (33 loc) · 745 Bytes
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
package main
import (
"fmt"
"os"
)
var log logger
type logger struct {
on bool
f *os.File
}
func (l *logger) TurnOn() {
var err error
if _, err := os.Stat("/tmp/bosh_complete"); err != nil {
if !os.IsNotExist(err) {
panic("Could not stat log dir: " + err.Error())
}
err = os.Mkdir("/tmp/bosh_complete", 0775)
if err != nil {
panic("Could not make log dir: " + err.Error())
}
}
l.f, err = os.OpenFile("/tmp/bosh_complete/log.txt", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
panic("Could not open logging file" + err.Error())
}
l.on = true
}
func (l logger) Write(f string, args ...interface{}) {
if !l.on {
return
}
_, _ = l.f.Write([]byte(fmt.Sprintf("%s\n", fmt.Sprintf(f, args...))))
}