Class: Panda::Core::Testing::Support::System::FerrumConsoleLogger::Message
- Inherits:
-
Object
- Object
- Panda::Core::Testing::Support::System::FerrumConsoleLogger::Message
- Defined in:
- lib/panda/core/testing/support/system/ferrum_console_logger.rb
Overview
Wrapper for a single console message
Instance Method Summary collapse
-
#format_argument(arg) ⇒ Object
Format a CDP RemoteObject argument.
-
#initialize(log_str) ⇒ Message
constructor
A new instance of Message.
-
#level ⇒ Object
Get the log level (error, warning, info, etc.).
-
#message ⇒ Object
Get the message text.
- #to_s ⇒ Object
Constructor Details
#initialize(log_str) ⇒ Message
55 56 57 58 59 |
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 55 def initialize(log_str) parts = log_str.strip.split(" ", 3) @raw = log_str @data = JSON.parse(parts[2]) end |
Instance Method Details
#format_argument(arg) ⇒ Object
Format a CDP RemoteObject argument
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 93 def format_argument(arg) case arg["type"] when "string" arg["value"] when "number", "boolean" arg["value"].to_s when "undefined" "undefined" when "object" if arg["subtype"] == "null" "null" else arg["description"] || "[Object]" end else arg["description"] || arg.inspect end end |
#level ⇒ Object
Get the log level (error, warning, info, etc.)
62 63 64 65 66 67 |
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 62 def level # Different CDP events structure level differently @data.dig("params", "entry", "level") || @data.dig("params", "type") || "log" end |
#message ⇒ Object
Get the message text
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 70 def # Handle different CDP event types if @data["method"] == "Runtime.exceptionThrown" exception = @data.dig("params", "exceptionDetails") if exception text = exception.dig("exception", "description") || exception["text"] location = "#{exception.dig("url")}:#{exception.dig("lineNumber")}" "#{text} (#{location})" else "Unknown exception" end elsif @data["method"] == "Log.entryAdded" @data.dig("params", "entry", "text") || "" elsif @data["method"] == "Runtime.consoleAPICalled" # Console API calls have arguments that need to be extracted args = @data.dig("params", "args") || [] args.map { |arg| format_argument(arg) }.join(" ") else @raw end end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/panda/core/testing/support/system/ferrum_console_logger.rb', line 112 def to_s "[#{level.upcase}] #{message}" end |