Skip to content

Commit

Permalink
Address the deprecation warnings from the logger
Browse files Browse the repository at this point in the history
This addresses the deprecation warning below:

  DEPRECATION WARNING: Bolding log text with a positional boolean is deprecated and will be removed in Rails 7.2. Use an option hash instead (eg. ).
  • Loading branch information
yuki24 committed Feb 5, 2024
1 parent e850ae2 commit 1cf8f10
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/graphql/client/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ class Client
# GraphQL::Client::LogSubscriber.attach_to :graphql
#
class LogSubscriber < ActiveSupport::LogSubscriber
SHOULD_USE_KWARGS = private_instance_methods.include?(:mode_from)

def query(event)
logger.info do
name = event.payload[:operation_name].gsub("__", "::")
type = event.payload[:operation_type].upcase
color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, true)

if SHOULD_USE_KWARGS
color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, bold: true)
else
color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, true)
end
end

logger.debug do
Expand All @@ -32,7 +39,12 @@ def error(event)
logger.error do
name = event.payload[:operation_name].gsub("__", "::")
message = event.payload[:message]
color("#{name} ERROR: #{message}", nil, true)

if SHOULD_USE_KWARGS
color("#{name} ERROR: #{message}", nil, bold: true)
else
color("#{name} ERROR: #{message}", nil, true)
end
end
end
end
Expand Down

0 comments on commit 1cf8f10

Please sign in to comment.