-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging.go
More file actions
48 lines (43 loc) · 1.09 KB
/
logging.go
File metadata and controls
48 lines (43 loc) · 1.09 KB
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 (
"log"
"os"
"sync/atomic"
)
var (
logger *log.Logger
debugEnabled atomic.Bool
)
func initLogger() *os.File {
f, err := os.OpenFile(resolvePath("incott.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
return nil
}
logger = log.New(f, "", log.Ldate|log.Ltime)
return f
}
// logInfo writes a message that is always recorded regardless of the debug toggle.
// Use for user-initiated actions: setting changes, auto-boost events, startup/shutdown.
func logInfo(format string, args ...any) {
if logger == nil {
return
}
if len(args) > 0 {
logger.Printf("[INFO] "+format, args...)
} else {
logger.Println("[INFO] " + format)
}
}
// logDebug writes a message only when the user has enabled debug mode.
// Use for device-level events: HID report bytes, poll responses, raw data.
func logDebug(format string, args ...any) {
if !debugEnabled.Load() || logger == nil {
return
}
if len(args) > 0 {
logger.Printf("[DEBUG] "+format, args...)
} else {
logger.Println("[DEBUG] " + format)
}
}