Class: ActiveShopifyGraphQL::Logging::GraphqlLogger
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- ActiveShopifyGraphQL::Logging::GraphqlLogger
- Defined in:
- lib/active_shopify_graphql/logging/graphql_logger.rb
Overview
Logs GraphQL queries with timing and cost information Uses ActiveSupport::LogSubscriber for consistent Rails-style log formatting
Constant Summary collapse
- YELLOW =
33- GREEN =
32- BLUE =
34- CYAN =
36- MAGENTA =
35
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.log(query:, duration_ms:, cost:, variables:) ⇒ Object
14 15 16 |
# File 'lib/active_shopify_graphql/logging/graphql_logger.rb', line 14 def self.log(query:, duration_ms:, cost:, variables:) new.log(query:, duration_ms:, cost:, variables:) end |
Instance Method Details
#log(query:, duration_ms:, cost:, variables:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_shopify_graphql/logging/graphql_logger.rb', line 18 def log(query:, duration_ms:, cost:, variables:) GraphqlRuntime.add(duration_ms:, cost: cost&.dig("requestedQueryCost")) name = color(" GraphQL (#{duration_ms.round(1)}ms)", YELLOW, bold: true) colored_query = color(query.gsub(/\s+/, " ").strip, graphql_color(query), bold: true) binds = variables.present? ? " #{variables.inspect}" : "" cost_info = "\n ↳ cost: #{cost}" if cost debug "#{name} #{colored_query}#{binds}#{cost_info}" end |