GraphQL is amazing. But one disadvantage is that with Ruby you lose some of the
logging that "just works" with REST. That is, all of the log messages have the
same controller (API::GraphqlController
) and the params are lost or
unstructured.
This gem aims to make is easy to include this information in logs messages.
Add this line to your application's Gemfile:
gem 'graphql-log_helper'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install graphql-log_helper
Add lograge to your Gemfile and include
the following in config/initializers/lograge.rb
—
Rails.application.configure do
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.custom_options = lambda do |event|
if event.payload[:controller] == 'GraphqlController'
Graphql::LogHelper.log_details(event.payload[:params])
else
{ params: event.payload[:params] }
end.compact
end
end
TODO
Bug reports and pull requests are welcome on GitHub at https://github.com/hoverinc/graphql-log_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Graphql::LogHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.