Explore documentation
Installing Logtail Ruby & Rails client
Logtail allows you to collect logs directly from any Ruby & Rails projects. Supported language versions are:
- Ruby 2.7.0 or newer
- Rails 6.1.4.2 or newer
Install Ruby Bundler
If you have Ruby bundler already installed, you can skip this step. Run the following command to install the ruby bundler:
sudo apt install ruby-bundler
Installing to Ruby project
To install Logtail to your Ruby project, run the following command:
bundle add logtail
This will install Logtail gem and create Gemfile
and Gemfile.lock
that are used to track the code dependencies.
Alternatively, add gem "logtail"
to your Gemfile
manually and then run bundle install
.
Installing to Rails project
To install Logtail to your Ruby on Rails project, run the following command
bundle add logtail-rails
Alternatively, add gem "logtail-rails"
to your Gemfile
manually and then run bundle install
How it works in action
Here is an example of how to send logs from your Ruby & Rails application to Logtail.
For a more detailed example, please see the Ruby + Logtail example project on GitHub or the Rails + Logtail example project on GitHub .
require "logtail"
http_device = Logtail::LogDevices::HTTP.new("<your-source-token>")
logger = Logtail::Logger.new(http_device)
logger.info("logtail is ready")
logger.warn(
"log structured data",
item: {
url: "https://fictional-store.com/item-123",
price: 100.00
}
)
{
"dt": "2021-03-29T11:24:54.788Z",
"level": "info",
"message": "logtail integration is ready",
"context": {
"runtime": {
"thread_id": 123,
"file": "script-file.rb",
"line": 6,
"frame": null,
"frame_label": "<main>"
},
"system": {
"hostname": "hostname"
"pid": 1234
}
}
}
{
"dt": "2021-03-29T11:24:54.788Z",
"level": "warn",
"message": "log structured data",
"item": {
"url": "https://fictional-store.com/item-123",
"price": 100.00
},
"context": {
"runtime": {
"thread_id": 123,
"file": "script-file.rb",
"line": 7,
"frame": null,
"frame_label": "<main>"
},
"system": {
"hostname": "hostname"
"pid": 1234
}
}
}