- Provides a minimal logging subsystem for TmuxAI using a process-global singleton logger.
- Owns creation, configuration, and lifecycle of the application's log output file.
- Exposes both instance methods (
(*Logger).Info/Error/Debug) and package-level convenience functions (logger.Info/Error/Debug) for call sites.
Loggerencapsulates:logFile *os.File(the writable destination file),logger *log.Logger(standard library logger withlog.LstdFlags),mu sync.Mutex(serializes writes and close operations).
- Package-level singleton state is
instance *Loggerwithonce sync.Onceto guarantee one-time initialization. Init()callsnewLogger()exactly once viaonce.Do;GetInstance()/global helpers assume initialization may occur elsewhere.- File location strategy is deterministic:
$HOME/.config/tmuxai/tmuxai.log, withMkdirAllfor the directory and append/create mode for the file. - Logging calls prepend severity tags (
[INFO],[ERROR],[DEBUG]) to formatted messages and delegate tolog.Logger.Printf.
Init→once.Do→newLogger:- Resolve
$HOMEviaos.UserHomeDir. - Ensure
~/.config/tmuxaiexists. - Open
tmuxai.logwith append/create/write flags. - Construct
log.Loggerand assign to globalinstance.
- Resolve
GetInstancereturns an error ifinstance == nil(not initialized).- Package-level
Info/Error/Debugfunctions checkinstance != niland forward to the singleton instance methods; otherwise they no-op. - Instance
Info/Error/Debuglockmu, format+print to file-backed logger, then unlock. Closelocksmuand closeslogFile.
- Imported by application entrypoints/components that need runtime log emission.
- Consumers should call
logger.Init()during startup before first logging; after that use either:- package-level
logger.Info(...)etc. (simplest), or logger.GetInstance()to obtain explicit*Loggerwhen dependency-injected usage is desired.
- package-level
- The log file path (
~/.config/tmuxai/tmuxai.log) is the primary external integration surface for operators and diagnostics tooling.