-
Notifications
You must be signed in to change notification settings - Fork 0
/
corecontext.go
47 lines (40 loc) · 988 Bytes
/
corecontext.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
package context
import (
"fmt"
"os"
"path/filepath"
"openshift-cluster-pooler/pkg/logging"
"openshift-cluster-pooler/pkg/utils"
)
type coreContext struct {
logsDir string
debug bool
logger *logging.LogHandler
}
func newCoreContext(name string, logsDir string, debug bool) *coreContext {
return &coreContext{
logsDir: logsDir,
debug: debug,
logger: logging.NewLogger(name, debug),
}
}
func (c coreContext) LogToFile(filename string, data []byte, subdirs ...string) error {
var dl string
dl = filepath.Join(c.logsDir, subdirs[0])
for _, elem := range subdirs[1:] {
dl = filepath.Join(dl, elem)
}
fl := filepath.Join(dl, filename)
_ = os.MkdirAll(dl, os.ModePerm)
c.logger.Info("file logger", "writing logs to file %s", fl)
if c.debug {
fmt.Println("logs : \n", string(data))
}
return utils.WriteFile(fl, data)
}
func (c coreContext) DebugEnabled() bool {
return c.debug
}
func (c coreContext) GetLogger() *logging.LogHandler {
return c.logger
}