Class: RosettAi::Desktop::GuiLogger
- Inherits:
-
Object
- Object
- RosettAi::Desktop::GuiLogger
- Defined in:
- lib/rosett_ai/desktop/gui_logger.rb
Overview
Structured GUI action logger for debugging and crash analysis.
Provides comprehensive logging of all GUI interactions including:
- Action invocation with parameters
- Success/failure outcomes with duration
- Widget events and state changes
- D-Bus operations
Log output is controlled by environment variables:
RAI_GUI_LOG=1 Enable logging to stderr
RAI_GUI_LOG_FILE=path Also log to file
RAI_GUI_LOG_LEVEL=debug Set log level (debug, info, warn, error)
Log format is JSON Lines for easy parsing and analysis.
Constant Summary collapse
- LEVELS =
Returns Supported level values.
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
- DEFAULT_LEVEL =
Returns Default log level.
:info
Class Method Summary collapse
-
.instance ⇒ GuiLogger
Get the singleton instance.
Instance Method Summary collapse
-
#action(name, context = {}) { ... } ⇒ Object
Log a complete action with automatic timing.
-
#action_end(name, context = {}) ⇒ Object
Log action end.
-
#action_start(name, context = {}) ⇒ Object
Log action start.
-
#callback(name, context = {}) ⇒ Object
Log a callback invocation.
-
#dbus_call(operation, context = {}) ⇒ Object
Log a D-Bus operation.
-
#debug(message, context = {}) ⇒ Object
Log debug message.
-
#enabled? ⇒ Boolean
Check if logging is enabled.
-
#error(message, error = nil, context = {}) ⇒ Object
Log error message.
-
#info(message, context = {}) ⇒ Object
Log info message.
-
#initialize ⇒ GuiLogger
constructor
A new instance of GuiLogger.
-
#warn(message, context = {}) ⇒ Object
Log warning message.
-
#widget_event(widget_type, event, context = {}) ⇒ Object
Log a widget event.
Constructor Details
#initialize ⇒ GuiLogger
Returns a new instance of GuiLogger.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 53 def initialize @enabled = ENV['RAI_GUI_LOG'] == '1' @log_file = ENV.fetch('RAI_GUI_LOG_FILE', nil) @level = parse_level(ENV.fetch('RAI_GUI_LOG_LEVEL', 'info')) @file_handle = nil @action_stack = [] @mutex = Mutex.new setup_file_logging if @log_file at_exit { cleanup } end |
Class Method Details
.instance ⇒ GuiLogger
Get the singleton instance.
42 43 44 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 42 def instance @instance ||= new end |
Instance Method Details
#action(name, context = {}) { ... } ⇒ Object
Log a complete action with automatic timing.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 78 def action(name, context = {}) return yield unless @enabled action_start(name, context) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin result = yield duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(2) action_end(name, status: :success, duration_ms: duration) result rescue StandardError => e duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(2) action_end(name, status: :error, duration_ms: duration, error: e.class.name, message: e.) raise end end |
#action_end(name, context = {}) ⇒ Object
Log action end.
111 112 113 114 115 116 117 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 111 def action_end(name, context = {}) return unless @enabled @mutex.synchronize { @action_stack.pop } level = context[:status] == :error ? :error : :info write_log(level, 'action_end', { action: name.to_s }.merge(context)) end |
#action_start(name, context = {}) ⇒ Object
Log action start.
100 101 102 103 104 105 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 100 def action_start(name, context = {}) return unless @enabled @mutex.synchronize { @action_stack.push(name.to_s) } write_log(:info, 'action_start', { action: name.to_s }.merge(context)) end |
#callback(name, context = {}) ⇒ Object
Log a callback invocation.
123 124 125 126 127 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 123 def callback(name, context = {}) return unless @enabled write_log(:debug, 'callback', { callback: name.to_s }.merge(context)) end |
#dbus_call(operation, context = {}) ⇒ Object
Log a D-Bus operation.
147 148 149 150 151 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 147 def dbus_call(operation, context = {}) return unless @enabled write_log(:debug, 'dbus_call', { operation: operation.to_s }.merge(context)) end |
#debug(message, context = {}) ⇒ Object
Log debug message.
157 158 159 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 157 def debug(, context = {}) write_log(:debug, 'debug', { message: }.merge(context)) end |
#enabled? ⇒ Boolean
Check if logging is enabled.
68 69 70 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 68 def enabled? @enabled end |
#error(message, error = nil, context = {}) ⇒ Object
Log error message.
182 183 184 185 186 187 188 189 190 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 182 def error(, error = nil, context = {}) data = { message: }.merge(context) if error data[:error_class] = error.class.name data[:error_message] = error. data[:backtrace] = error.backtrace&.first(5) end write_log(:error, 'error', data) end |
#info(message, context = {}) ⇒ Object
Log info message.
165 166 167 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 165 def info(, context = {}) write_log(:info, 'info', { message: }.merge(context)) end |
#warn(message, context = {}) ⇒ Object
Log warning message.
173 174 175 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 173 def warn(, context = {}) write_log(:warn, 'warn', { message: }.merge(context)) end |
#widget_event(widget_type, event, context = {}) ⇒ Object
Log a widget event.
134 135 136 137 138 139 140 141 |
# File 'lib/rosett_ai/desktop/gui_logger.rb', line 134 def (, event, context = {}) return unless @enabled write_log(:debug, 'widget_event', { widget: .to_s, event: event.to_s }.merge(context)) end |