Logging From Ruby
This documentation outlines how to configure logging with your AppSignal for Ruby integration.
Configure Logging
You do not need to create a log source to send logs from the AppSignal for Ruby integration. An "application" log source will be created automatically.
Rails Logger
You can configure the Rails framework to send logs to AppSignal in an initializer file like config/initializers/logging.rb
:
Using multiple logging backends
To send logs to both AppSignal's logger and Rails' default logger, use our logger's .broadcast_to
helper:
We do not recommend using Rails' built-in broadcast logger feature, due to compatibility issues when used alongside tagged logging.
Tagged logging support
The use of ActiveSupport::TaggedLogging
in the above examples enables support for Rails' log tags. For example, if you wish to add the request ID tag to the log messages, add it to the config.log_tags
array in the config/application.rb
file:
Using Lograge
The Lograge library is a popular solution for ingesting structured Rails request logs.
After adding the lograge
gem, you can configure it in config/initializers/lograge.rb
to send logs to AppSignal:
Sidekiq Logger
You can configure Sidekiq to send its logs to AppSignal, including the logs emitted by your background jobs:
Ruby Logger
To send logs to AppSignal as you would with Ruby's Logger
class, you will need to create an instance of Appsignal::Logger
and provide it with a groupname
that defines where you are logging from, for example, if we were logging from a helper for invoicing clients:
Semantic Logger
The Semantic Logger library provides a comprehensive logging solution for Ruby and Rails applications.
After adding the semantic_logger
gem, you can configure it to send logs to AppSignal as follows:
Usage
Sending Logs
Like the Ruby/Rails Logger
class, you can define the severity level of your logs by using fatal
, error
, warn
, info
, and debug
:
You can define custom attributes to send log information that can be used when filtering and querying logs:
You can query and filter on message contents and attribute values from within the Log Management tool.
Once configured, the desired attributes will be sent to AppSignal as log_tags
, and be queryable in the AppSignal logging interface.
Default Logger Attributes
When initializing the AppSignal logger, you can provide default attributes that will be included in all log messages:
The attributes provided when initializing the logger will be included in all log messages sent from that logger instance. Attributes provided with the log message will be merged with the default logger attributes.
When both the logger and the log message provide the same attribute, the log message's attribute will override the default logger attribute.
Logfmt and JSON
The log format can be specified when creating a logger. For Logfmt:
For JSON:
In both of the examples above, a filterable category attribute with the value "blog" will be logged.
Filtering Logs
You can use the ignore_logs
configuration option to ignore log lines. See our Ignore Logs guide to learn more.
Need Help?
After configuring your Ruby application to send logs, logs should appear in AppSignal. If you are unsure about this step or AppSignal is not receiving any logs, you can always reach out for assistance. We'll help get you back on track!