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 likeconfig/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:
Tagged logging support
The use ofActiveSupport::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 thelograge gem, you can configure it in config/initializers/lograge.rb to send logs to AppSignal:
Sinatra Logger
You can configure Sinatra to send request logs to AppSignal using Rack’s CommonLogger middleware. Configure it like shown below. Consider if request logs contain useful information for you, read our what logs should I store learning center article.Using multiple logging backends
To send logs to both AppSignal’s logger andSTDOUT, use our logger’s .broadcast_to helper:
Sidekiq Logger
You can configure Sidekiq to send its logs to AppSignal, including the logs emitted by your background jobs:Using multiple logging backends
To send logs to both AppSignal’s logger andSTDOUT, use our logger’s .broadcast_to helper:
Ruby Logger
To send logs to AppSignal as you would with Ruby’sLogger 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:
Using multiple logging backends
To send logs to both AppSignal’s logger andSTDOUT, use our logger’s .broadcast_to helper:
Semantic Logger
The Semantic Logger library provides a comprehensive logging solution for Ruby and Rails applications. After adding thesemantic_logger gem, you can configure it to send logs to AppSignal as follows:
Using multiple logging backends
To send logs to both AppSignal’s logger andSTDOUT, add another appender using the add_appender method:
Usage
Sending Logs
Like the Ruby/RailsLogger class, you can define the severity level of your logs by using fatal, error, warn, info, and debug:
Default Logger Attributes
When initializing the AppSignal logger, you can provide default attributes that will be included in all log messages:Formats
Auto detected format
The AppSignal for Ruby gem will automatically detect the log line’s format as JSON, Logfmt or plaintext by default, and parse attributes from it. You don’t need to manually set the log format, unless it’s not being detected properly. Please also notify us if this isn’t working automatically.Logfmt
The AppSignal Logger can be explicitly configured to expect the line to be formatted as Logfmt and parse attributes from it. Use this option when using an older AppSignal for Ruby gem version, which does not support automatic format detection. The log format can be specified when creating a logger. When initializing the AppSignal logger pass the Logfmt constant in the format option.JSON
The AppSignal Logger can be explicitly configured to expect the line to be formatted as JSON and parse attributes from it. Use this option when using an older AppSignal for Ruby gem version, which does not support automatic format detection. The log format can be specified when creating a logger. When initializing the AppSignal logger pass the JSON constant in the format option.Filtering Logs
You can use theignore_logs configuration option to ignore log lines. See our Ignore Logs guide to learn more.