
Rails version 6.1.4.2 or higher is required.
Ruby version 2.7.0 or higher is required.
Where do you want to collect your Ruby logs from?
Collect logs from your Rails application.
Install Better Stack Rails Gem:
bundle add logtail-rails
Set up Better Stack Rails Gem in config/application.rb
:
module YourProject
class Application < Rails::Application
# ...
# configuration of your project
# ...
config.logger = Logtail::Logger.create_default_logger("$SOURCE_TOKEN")
end
end
To optionally filter sensitive parameters and/or HTTP headers, create a new initializer:
# Be sure to restart your server when you modify this file.
# Configure parameters to be filtered from the log file. Use this to limit dissemination of sensitive information.
# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
Rails.application.config.filter_parameters += [
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
]
# Configure HTTP headers to be filtered from the log. Use this to limit dissemination of sensitive information.
Logtail::Integrations::Rack::HTTPEvents.http_header_filters = [
:authorization, :proxy_authorization, :cookie
]
Use Rails logger as usual:
Rails.logger.error("Something bad happened.")
Rails.logger.warn("Log message wih structured logging.", {
item: "Orange Soda",
price: 100.00
})
You should see your logs in Logtail -> Live tail.
Rails version 6.1.4.2 or higher is required.
Ruby version 2.7.0 or higher is required.
Collect logs from your Ruby code.
Install Better Stack Gem:
bundle add logtail
Set up Better Stack Ruby client:
require "logtail"
http_device = Logtail::LogDevices::HTTP.new("$SOURCE_TOKEN")
logger = Logtail::Logger.new(http_device)
Use Ruby logger as usual:
logger.error("Something bad happened.")
logger.warn("Log message with structured logging.", {
item: "Orange Soda",
price: 100.00
})
# Close logger to ensure that all logs are sent to Logtail
logger.close
You should see your logs in Logtail -> Live tail.
Ruby version 2.7.0 or higher is required.
Please let us know at hello@betterstack.com.
We're happy to help! ๐
Interested in learning more about log levels in Rails?
Check out our Intro guide to Ruby on Rails logging.
Add custom data to multiple log lines using with
block:
Logtail.with_context(user: { id: 123 }) do
Rails.logger.info('User logged in.')
Rails.logger.info('User bought a gem.')
end
Logtail.with_context(user: { id: 123 }) do
logger.info('User logged in.')
logger.info('User bought a gem.')
end
You can prevent logger from sending certain logs to Better Stack:
# in your config/application.rb
config.logtail.filter_sent_to_better_stack do |log_entry|
log_entry.context_snapshot[:http][:path].start_with?('/_')
end
# anywhere before sending the logs
Logtail.config.filter_sent_to_better_stack do |log_entry|
log_entry.message.include?("IGNORE")
end
See Logtail::LogEntry
for available attributes of the block parameter.