MCPcopy
hub / github.com/slimtoolkit/slim / configureLogger

Function configureLogger

pkg/app/sensor/logger.go:14–43  ·  view source on GitHub ↗
(
	enableDebug bool,
	levelName string,
	format string,
	logFile string,
)

Source from the content-addressed store, hash-verified

12)
13
14func configureLogger(
15 enableDebug bool,
16 levelName string,
17 format string,
18 logFile string,
19) error {
20 if err := setLogLevel(enableDebug, levelName); err != nil {
21 return fmt.Errorf("failed to set log-level: %v", err)
22 }
23
24 if err := setLogFormat(format); err != nil {
25 return fmt.Errorf("failed to set log format: %v", err)
26 }
27
28 if len(logFile) > 0 {
29 // This touch is not ideal - need to understand how to merge this logic with artifacts.PrepareEnv().
30 if err := fsutil.Touch(logFile); err != nil {
31 return fmt.Errorf("failed to set log output destination to %q, touch failed with: %v", logFile, err)
32 }
33
34 f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
35 if err != nil {
36 return fmt.Errorf("failed to set log output destination to %q: %w", logFile, err)
37 }
38
39 log.SetOutput(f)
40 }
41
42 return nil
43}
44
45func setLogFormat(format string) error {
46 switch format {

Callers 1

RunFunction · 0.85

Calls 3

TouchFunction · 0.92
setLogLevelFunction · 0.85
setLogFormatFunction · 0.85

Tested by

no test coverage detected