summaryrefslogtreecommitdiff
path: root/internal/task/debug.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-25 17:38:03 +0300
committerPaul Buetow <paul@buetow.org>2026-06-25 17:38:03 +0300
commit6ba890330df991eb12cd313a42cf2704f3c30227 (patch)
tree52f0c28ed49bbb74a535822001acb2e6914e1f65 /internal/task/debug.go
parentc8c3307e9e636406491572d9b8dda3a84929613d (diff)
Refactor task package layout for 4r0
Diffstat (limited to 'internal/task/debug.go')
-rw-r--r--internal/task/debug.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/task/debug.go b/internal/task/debug.go
new file mode 100644
index 0000000..061dac2
--- /dev/null
+++ b/internal/task/debug.go
@@ -0,0 +1,42 @@
+package task
+
+import (
+ "io"
+ "os"
+)
+
+// debugConfig groups the optional debug-logging state for the task package.
+// Collecting related vars into a struct makes the mutable state explicit and
+// allows the logger to be swapped or reset cleanly without touching unrelated
+// package globals.
+type debugConfig struct {
+ writer io.Writer
+ file *os.File // tracked separately so it can be closed on reconfiguration
+}
+
+// dbg holds the active debug-logging configuration for this package.
+// It is written only via SetDebugLog and read only in run().
+var dbg debugConfig
+
+// SetDebugLog enables logging of executed commands to the given file.
+// Passing an empty path disables logging and closes any previously opened file.
+func SetDebugLog(path string) error {
+ // Close existing debug file if open before re-configuring.
+ if dbg.file != nil {
+ _ = dbg.file.Close()
+ dbg.file = nil
+ dbg.writer = nil
+ }
+
+ if path == "" {
+ return nil
+ }
+
+ f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
+ if err != nil {
+ return err
+ }
+ dbg.file = f
+ dbg.writer = f
+ return nil
+}