Module: Clacky::Logger
- Defined in:
- lib/clacky/utils/logger.rb
Overview
Thread-safe daily-rotating file logger.
Log files are written to ~/.clacky/logger/clacky-YYYY-MM-DD.log. At most 7 daily log files are kept; older ones are pruned automatically.
Usage (anywhere in the codebase):
Clacky::Logger.info("server started")
Clacky::Logger.debug("tool result", tool: "shell", exit_code: 0)
Clacky::Logger.warn("retry attempt", n: 3)
Clacky::Logger.error("unhandled exception", error: e)
Constant Summary collapse
- LOG_DIR =
File.join(Dir.home, ".clacky", "logger").freeze
- MAX_LOG_FILES =
7- MUTEX =
Mutex.new
- LEVELS =
Level constants (numeric, for future filtering)
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
- CONSOLE_MIN_LEVEL =
Minimum level to echo to $stderr when console output is enabled. :debug → all; :info → info/warn/error; :warn → warn/error only
:info
Class Attribute Summary collapse
-
.console ⇒ Object
writeonly
Enable/disable echoing log lines to $stderr (in addition to the file).
Class Method Summary collapse
-
.debug(message, **context) ⇒ Object
Log at DEBUG level.
-
.error(message, **context) ⇒ Object
Log at ERROR level.
-
.info(message, **context) ⇒ Object
Log at INFO level.
-
.warn(message, **context) ⇒ Object
Log at WARN level.
Class Attribute Details
.console=(value) ⇒ Object (writeonly)
Enable/disable echoing log lines to $stderr (in addition to the file). Call Clacky::Logger.console = true from server startup to activate.
32 33 34 |
# File 'lib/clacky/utils/logger.rb', line 32 def console=(value) @console = value end |
Class Method Details
.debug(message, **context) ⇒ Object
Log at DEBUG level.
39 40 41 |
# File 'lib/clacky/utils/logger.rb', line 39 def debug(, **context) write_log(:debug, , context) end |
.error(message, **context) ⇒ Object
Log at ERROR level. Accepts an optional :error key that may be an Exception; its backtrace is appended automatically.
55 56 57 |
# File 'lib/clacky/utils/logger.rb', line 55 def error(, **context) write_log(:error, , context) end |
.info(message, **context) ⇒ Object
Log at INFO level.
44 45 46 |
# File 'lib/clacky/utils/logger.rb', line 44 def info(, **context) write_log(:info, , context) end |
.warn(message, **context) ⇒ Object
Log at WARN level.
49 50 51 |
# File 'lib/clacky/utils/logger.rb', line 49 def warn(, **context) write_log(:warn, , context) end |