logtail-rails 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +91 -4
- data/example-project/.gitattributes +7 -0
- data/example-project/.gitignore +35 -0
- data/example-project/Gemfile +74 -0
- data/example-project/README.md +211 -0
- data/example-project/Rakefile +6 -0
- data/example-project/app/assets/config/manifest.js +4 -0
- data/example-project/app/assets/images/.keep +0 -0
- data/example-project/app/assets/stylesheets/application.css +15 -0
- data/example-project/app/channels/application_cable/channel.rb +4 -0
- data/example-project/app/channels/application_cable/connection.rb +4 -0
- data/example-project/app/controllers/application_controller.rb +2 -0
- data/example-project/app/controllers/concerns/.keep +0 -0
- data/example-project/app/controllers/example_controller.rb +40 -0
- data/example-project/app/helpers/application_helper.rb +2 -0
- data/example-project/app/helpers/example_helper.rb +2 -0
- data/example-project/app/javascript/application.js +3 -0
- data/example-project/app/javascript/controllers/application.js +9 -0
- data/example-project/app/javascript/controllers/hello_controller.js +7 -0
- data/example-project/app/javascript/controllers/index.js +11 -0
- data/example-project/app/jobs/application_job.rb +7 -0
- data/example-project/app/mailers/application_mailer.rb +4 -0
- data/example-project/app/models/application_record.rb +3 -0
- data/example-project/app/models/concerns/.keep +0 -0
- data/example-project/app/views/example/index.html.erb +3 -0
- data/example-project/app/views/example/send_logs.html.erb +4 -0
- data/example-project/app/views/layouts/application.html.erb +15 -0
- data/example-project/app/views/layouts/mailer.html.erb +13 -0
- data/example-project/app/views/layouts/mailer.text.erb +1 -0
- data/example-project/bin/bundle +114 -0
- data/example-project/bin/importmap +4 -0
- data/example-project/bin/rails +4 -0
- data/example-project/bin/rake +4 -0
- data/example-project/bin/setup +33 -0
- data/example-project/config/application.rb +24 -0
- data/example-project/config/boot.rb +4 -0
- data/example-project/config/cable.yml +11 -0
- data/example-project/config/credentials.yml.enc +1 -0
- data/example-project/config/database.yml +25 -0
- data/example-project/config/environment.rb +5 -0
- data/example-project/config/environments/development.rb +70 -0
- data/example-project/config/environments/production.rb +93 -0
- data/example-project/config/environments/test.rb +60 -0
- data/example-project/config/importmap.rb +7 -0
- data/example-project/config/initializers/assets.rb +12 -0
- data/example-project/config/initializers/content_security_policy.rb +25 -0
- data/example-project/config/initializers/filter_parameter_logging.rb +8 -0
- data/example-project/config/initializers/inflections.rb +16 -0
- data/example-project/config/initializers/permissions_policy.rb +11 -0
- data/example-project/config/locales/en.yml +33 -0
- data/example-project/config/puma.rb +43 -0
- data/example-project/config/routes.rb +7 -0
- data/example-project/config/storage.yml +34 -0
- data/example-project/config.ru +6 -0
- data/example-project/db/seeds.rb +7 -0
- data/example-project/lib/assets/.keep +0 -0
- data/example-project/lib/tasks/.keep +0 -0
- data/example-project/log/.keep +0 -0
- data/example-project/public/404.html +67 -0
- data/example-project/public/422.html +67 -0
- data/example-project/public/500.html +66 -0
- data/example-project/public/apple-touch-icon-precomposed.png +0 -0
- data/example-project/public/apple-touch-icon.png +0 -0
- data/example-project/public/favicon.ico +0 -0
- data/example-project/public/robots.txt +1 -0
- data/example-project/storage/.keep +0 -0
- data/example-project/test/application_system_test_case.rb +5 -0
- data/example-project/test/channels/application_cable/connection_test.rb +11 -0
- data/example-project/test/controllers/.keep +0 -0
- data/example-project/test/fixtures/files/.keep +0 -0
- data/example-project/test/helpers/.keep +0 -0
- data/example-project/test/integration/.keep +0 -0
- data/example-project/test/mailers/.keep +0 -0
- data/example-project/test/models/.keep +0 -0
- data/example-project/test/system/.keep +0 -0
- data/example-project/test/test_helper.rb +13 -0
- data/example-project/tmp/.keep +0 -0
- data/example-project/tmp/pids/.keep +0 -0
- data/example-project/tmp/storage/.keep +0 -0
- data/example-project/vendor/.keep +0 -0
- data/example-project/vendor/javascript/.keep +0 -0
- data/lib/logtail-rails/log_entry.rb +14 -0
- data/lib/logtail-rails/logger.rb +19 -1
- data/lib/logtail-rails/overrides/active_support_tagged_logging.rb +1 -1
- data/lib/logtail-rails/version.rb +1 -1
- data/lib/logtail-rails.rb +6 -2
- data/logtail-rails.gemspec +6 -3
- metadata +115 -7
- data/lib/logtail-rails/tasks/logtail.rake +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eb050c970571683d40dcd025672d9fb0eebcc72261627e7716115b7e16bd3a4
|
4
|
+
data.tar.gz: abc54338cfdb59ddc885fc5c3589119b21e9ce6a7bb6d7f8b73301f6f94f2233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 493ff5967c0a198b4667bd693074267f4ebe6e543363496a93825e41dd03736ced0e85357c207e1c3ce225375527c9feef424e51f0bd040b977403326e410c6a
|
7
|
+
data.tar.gz: d5886072cbfbd130164e68bc7d23c3aaf1e335ee2b8dbb5e115c380c57ae437e6d45ba8797c824847014e3372b4c01600692ede1701c0c283721022c01e18640
|
data/README.md
CHANGED
@@ -1,10 +1,97 @@
|
|
1
|
-
#
|
1
|
+
# Logtail - Ruby on Rails Logging Made Easy
|
2
|
+
|
3
|
+
[![Logtail ruby dashboard](https://user-images.githubusercontent.com/19272921/154085622-59997d5a-3f91-4bc9-a815-3b8ead16d28d.jpeg)](https://betterstack.com/logtail)
|
2
4
|
|
3
5
|
[![ISC License](https://img.shields.io/badge/license-ISC-ff69b4.svg)](LICENSE.md)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/logtail-ruby.svg)](https://badge.fury.io/rb/logtail-ruby)
|
4
7
|
[![Build Status](https://github.com/logtail/logtail-ruby-rails/workflows/build/badge.svg)](https://github.com/logtail/logtail-ruby-rails/actions?query=workflow%3Abuild)
|
5
8
|
|
6
|
-
|
7
|
-
the [rails](https://github.com/rails/rails) framework, turning your rails logs into rich structured events.
|
9
|
+
Collect logs directly from your Ruby on Rails projects. To start logging Ruby projects explore the [Logtail Ruby library](https://github.com/logtail/logtail-ruby).
|
8
10
|
|
9
|
-
|
11
|
+
[Logtail](https://betterstack.com/logtail) is a hosted service that centralizes all of your logs into one place. Allowing for analysis, correlation and filtering with SQL. Actionable Grafana dashboards and collaboration come built-in. Logtail works with [any language or platform and any data source](https://betterstack.com/docs/logs/).
|
10
12
|
|
13
|
+
### Features
|
14
|
+
- Simple integration.
|
15
|
+
- Support for structured logging and events.
|
16
|
+
- Automatically captures useful context.
|
17
|
+
- Performant, light weight, with a thoughtful design.
|
18
|
+
|
19
|
+
### Supported language versions
|
20
|
+
- Ruby 2.7.0 or newer
|
21
|
+
- Rails 6.1.4.2 or newer
|
22
|
+
|
23
|
+
# Installation
|
24
|
+
Install the Logtail Ruby on Rails client library, run the following command:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
bundle add logtail-rails
|
28
|
+
```
|
29
|
+
|
30
|
+
Alternatively, add `gem "logtail-rails"` to your `Gemfile` manually and then run `bundle install`.
|
31
|
+
|
32
|
+
Then add following configuration line into your `config/application.rb`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
module YourProject
|
36
|
+
class Application < Rails::Application
|
37
|
+
# ...
|
38
|
+
# configuration of your project
|
39
|
+
# ...
|
40
|
+
|
41
|
+
config.logger = Logtail::Logger.create_default_logger("<SOURCE_TOKEN>")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
*Don't forget to replace `<SOURCE_TOKEN>` with your actual source token which you can find by going to [Better Stack Logs](https://logs.betterstack.com/dashboard) -> Source -> Edit.*
|
47
|
+
|
48
|
+
---
|
49
|
+
|
50
|
+
# Example project
|
51
|
+
|
52
|
+
To help you get started with using Logtail in your Ruby on Rails projects, we have prepared a simple program that showcases the usage of Logtail logger.
|
53
|
+
|
54
|
+
## Download and install the example project
|
55
|
+
|
56
|
+
You can download the [example project](https://github.com/logtail/logtail-ruby-rails/tree/main/example-project) from GitHub directly or you can clone it to a select directory. Make sure you are in the projects directory and run the following command:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
bundle install
|
60
|
+
```
|
61
|
+
|
62
|
+
This will install all dependencies listed in the `Gemfile.lock` file.
|
63
|
+
|
64
|
+
Then replace `<SOURCE_TOKEN>` in `config/application.rb` with your actual source token which you can find by going to [Better Stack Logs](https://logs.betterstack.com/dashboard) -> Source -> Edit.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
config.logger = Logtail::Logger.create_default_logger("<YOUR_ACTUAL_SOURCE_TOKEN>")
|
68
|
+
```
|
69
|
+
|
70
|
+
## Run the example project
|
71
|
+
|
72
|
+
To run the example application, run the following command:
|
73
|
+
|
74
|
+
```bash
|
75
|
+
rails server
|
76
|
+
```
|
77
|
+
|
78
|
+
This will open a local server [127.0.0.1:3000.](http://127.0.0.1:3000/) On the main page, click the "Let's go!" button to generate test logs.
|
79
|
+
|
80
|
+
You should see the following output:
|
81
|
+
|
82
|
+
```bash
|
83
|
+
All done!
|
84
|
+
Log into your Logtail account to check your logs.
|
85
|
+
```
|
86
|
+
|
87
|
+
This will create a total of 6 different logs, each corresponding to a different log level and one with additional structured data. You can review these logs in Logtail.
|
88
|
+
|
89
|
+
## Explore how example project works
|
90
|
+
|
91
|
+
Learn how to setup Ruby logging by exploring the workings of the [example project](https://github.com/logtail/logtail-ruby-rails/tree/main/example-project) in detail.
|
92
|
+
|
93
|
+
---
|
94
|
+
|
95
|
+
## Get in touch
|
96
|
+
|
97
|
+
Have any questions? Please explore the Better Stack [documentation](https://betterstack.com/docs/logs/) or contact our [support](https://betterstack.com/help).
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-*
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*
|
16
|
+
/tmp/*
|
17
|
+
!/log/.keep
|
18
|
+
!/tmp/.keep
|
19
|
+
|
20
|
+
# Ignore pidfiles, but keep the directory.
|
21
|
+
/tmp/pids/*
|
22
|
+
!/tmp/pids/
|
23
|
+
!/tmp/pids/.keep
|
24
|
+
|
25
|
+
# Ignore uploaded files in development.
|
26
|
+
/storage/*
|
27
|
+
!/storage/.keep
|
28
|
+
/tmp/storage/*
|
29
|
+
!/tmp/storage/
|
30
|
+
!/tmp/storage/.keep
|
31
|
+
|
32
|
+
/public/assets
|
33
|
+
|
34
|
+
# Ignore master key for decrypting credentials and more.
|
35
|
+
/config/master.key
|
@@ -0,0 +1,74 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
ruby "3.1.2"
|
5
|
+
|
6
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
7
|
+
gem "rails", "~> 7.0.6"
|
8
|
+
|
9
|
+
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
|
10
|
+
gem "sprockets-rails"
|
11
|
+
|
12
|
+
# Use sqlite3 as the database for Active Record
|
13
|
+
gem "sqlite3", "~> 1.4"
|
14
|
+
|
15
|
+
# Use the Puma web server [https://github.com/puma/puma]
|
16
|
+
gem "puma", "~> 5.0"
|
17
|
+
|
18
|
+
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
|
19
|
+
gem "importmap-rails"
|
20
|
+
|
21
|
+
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
|
22
|
+
gem "turbo-rails"
|
23
|
+
|
24
|
+
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
|
25
|
+
gem "stimulus-rails"
|
26
|
+
|
27
|
+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
28
|
+
gem "jbuilder"
|
29
|
+
|
30
|
+
# Use Redis adapter to run Action Cable in production
|
31
|
+
gem "redis", "~> 4.0"
|
32
|
+
|
33
|
+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
34
|
+
# gem "kredis"
|
35
|
+
|
36
|
+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
37
|
+
# gem "bcrypt", "~> 3.1.7"
|
38
|
+
|
39
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
40
|
+
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
|
41
|
+
|
42
|
+
# Reduces boot times through caching; required in config/boot.rb
|
43
|
+
gem "bootsnap", require: false
|
44
|
+
|
45
|
+
# Use Sass to process CSS
|
46
|
+
# gem "sassc-rails"
|
47
|
+
|
48
|
+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
49
|
+
# gem "image_processing", "~> 1.2"
|
50
|
+
|
51
|
+
group :development, :test do
|
52
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
53
|
+
gem "debug", platforms: %i[ mri mingw x64_mingw ]
|
54
|
+
end
|
55
|
+
|
56
|
+
group :development do
|
57
|
+
# Use console on exceptions pages [https://github.com/rails/web-console]
|
58
|
+
gem "web-console"
|
59
|
+
|
60
|
+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
|
61
|
+
# gem "rack-mini-profiler"
|
62
|
+
|
63
|
+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
64
|
+
# gem "spring"
|
65
|
+
end
|
66
|
+
|
67
|
+
group :test do
|
68
|
+
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
|
69
|
+
gem "capybara"
|
70
|
+
gem "selenium-webdriver"
|
71
|
+
gem "webdrivers"
|
72
|
+
end
|
73
|
+
|
74
|
+
gem "logtail-rails", "~> 0.1.7"
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# Logtail Ruby on Rails example project
|
2
|
+
|
3
|
+
To help you get started with using Logtail in your Ruby on Rails projects, we have prepared a simple program that showcases the usage of Logtail logger.
|
4
|
+
|
5
|
+
## Download and install the example project
|
6
|
+
You can download the example project from GitHub directly or you can clone it to a select directory. Make sure you are in the projects directory and run the following command:
|
7
|
+
|
8
|
+
```bash
|
9
|
+
bundle install
|
10
|
+
```
|
11
|
+
|
12
|
+
This will install all dependencies listed in the `Gemfile.lock` file.
|
13
|
+
|
14
|
+
Then replace `<SOURCE_TOKEN>` in `config/application.rb` with your actual source token which you can find by going to [Better Stack](https://logs.betterstack.com/) -> Sources -> Edit.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
config.logger = Logtail::Logger.create_default_logger("<YOUR_ACTUAL_SOURCE_TOKEN>")
|
18
|
+
```
|
19
|
+
|
20
|
+
## Run the example project
|
21
|
+
|
22
|
+
To run the example application, run the following command:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
rails server
|
26
|
+
```
|
27
|
+
|
28
|
+
This will open a local server [127.0.0.1:3000.](http://127.0.0.1:3000/) On the main page, click the "Let's go!" button to generate test logs.
|
29
|
+
|
30
|
+
You should see the following output:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
All done!
|
34
|
+
Log into your Logtail account to check your logs.
|
35
|
+
```
|
36
|
+
|
37
|
+
This will create a total of 6 different logs, each corresponding to a different log level and one with additional structured data. You can review these logs in Logtail.
|
38
|
+
|
39
|
+
# Logging
|
40
|
+
|
41
|
+
To send logs to Logtail use the `Rails.logger` logger. It provides 5 logging methods for the 5 default log levels. The log levels and their method are:
|
42
|
+
|
43
|
+
- **DEBUG** - Send debug messages using the `debug()` method
|
44
|
+
- **INFO** - Send informative messages about the application progress using the `info()` method
|
45
|
+
- **WARN** - Report non-critical issues using the `warn()` method
|
46
|
+
- **ERROR** - Send messages about serious problems using the `error()` method
|
47
|
+
- **FATAL** - Send messages about fatal events that caused the app to crash using the `fatal()` method
|
48
|
+
|
49
|
+
## Logging example
|
50
|
+
|
51
|
+
In this example, we will send two logs - **DEBUG** and **INFO**
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# Send debug logs messages using the debug() method
|
55
|
+
Rails.logger.debug("Logtail is ready!")
|
56
|
+
|
57
|
+
# Send informative messages about interesting events using the info() method
|
58
|
+
Rails.logger.info("I am using Logtail!")
|
59
|
+
```
|
60
|
+
|
61
|
+
This will create the following output:
|
62
|
+
|
63
|
+
```json
|
64
|
+
{
|
65
|
+
"dt": "2021-03-29T11:24:54.788Z",
|
66
|
+
"level": "debug",
|
67
|
+
"message": "Logtail is ready!",
|
68
|
+
"context": {
|
69
|
+
"runtime": {
|
70
|
+
"thread_id": 123,
|
71
|
+
"file": "main.rb",
|
72
|
+
"line": 6,
|
73
|
+
"frame": null,
|
74
|
+
"frame_label": "<main>"
|
75
|
+
},
|
76
|
+
"system": {
|
77
|
+
"hostname": "hostname",
|
78
|
+
"pid": 1234
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
{
|
84
|
+
"dt": "2021-03-29T11:24:54.788Z",
|
85
|
+
"level": "info",
|
86
|
+
"message": "I am using Logtail!",
|
87
|
+
"context": {
|
88
|
+
"runtime": {
|
89
|
+
"thread_id": 123,
|
90
|
+
"file": "main.rb",
|
91
|
+
"line": 6,
|
92
|
+
"frame": null,
|
93
|
+
"frame_label": "<main>"
|
94
|
+
},
|
95
|
+
"system": {
|
96
|
+
"hostname": "hostname",
|
97
|
+
"pid": 1234
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
103
|
+
## Log structured data
|
104
|
+
|
105
|
+
You can also log additional structured data. This can help you provide additional information when debugging and troubleshooting your application. You can provide this data as the second argument to any logging method.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
# Send messages about worrying events using the warn() method
|
109
|
+
# You can also log additional structured data
|
110
|
+
Rails.logger.warn(
|
111
|
+
"log structured data",
|
112
|
+
item: {
|
113
|
+
url: "https://fictional-store.com/item-123",
|
114
|
+
price: 100.00
|
115
|
+
}
|
116
|
+
)
|
117
|
+
```
|
118
|
+
|
119
|
+
This will create the following output:
|
120
|
+
|
121
|
+
```json
|
122
|
+
{
|
123
|
+
"dt": "2021-03-29T11:24:54.788Z",
|
124
|
+
"level": "warn",
|
125
|
+
"message": "log structured data",
|
126
|
+
"item": {
|
127
|
+
"url": "https://fictional-store.com/item-123",
|
128
|
+
"price": 100.00
|
129
|
+
},
|
130
|
+
"context": {
|
131
|
+
"runtime": {
|
132
|
+
"thread_id": 123,
|
133
|
+
"file": "main.rb",
|
134
|
+
"line": 7,
|
135
|
+
"frame": null,
|
136
|
+
"frame_label": "<main>"
|
137
|
+
},
|
138
|
+
"system": {
|
139
|
+
"hostname": "hostname",
|
140
|
+
"pid": 1234
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
```
|
145
|
+
|
146
|
+
## Context
|
147
|
+
|
148
|
+
We add information about the current runtime environment and the current process into a `context` field of the logged item by default.
|
149
|
+
|
150
|
+
If you want to add custom information to all logged items (e.g., the ID of the current user), you can do so by adding a custom context:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
# Provide context to the logs
|
154
|
+
Logtail.with_context(user: { id: 123 }) do
|
155
|
+
Rails.logger.info('new subscription')
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
This will generate the following JSON output:
|
160
|
+
|
161
|
+
```json
|
162
|
+
{
|
163
|
+
"dt": "2021-03-29T11:24:54.788Z",
|
164
|
+
"level": "warn",
|
165
|
+
"message": "new subscription",
|
166
|
+
"context": {
|
167
|
+
"runtime": {
|
168
|
+
"thread_id": 123456,
|
169
|
+
"file": "main.rb",
|
170
|
+
"line": 2,
|
171
|
+
"frame": null,
|
172
|
+
"frame_label": "<main>"
|
173
|
+
},
|
174
|
+
"system": {
|
175
|
+
"hostname": "hostname",
|
176
|
+
"pid": 1234
|
177
|
+
},
|
178
|
+
"user": {
|
179
|
+
"id": 123
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
```
|
184
|
+
|
185
|
+
We will automatically add the information about the current user to each log if you're using Ruby on Rails and the Devise gem.
|
186
|
+
|
187
|
+
If you're not using Devise or you want to log some additional information for every request your Rails app handles, you can easily implement this using Rails' `around_action` in your application controller. A simple implementation could look like this:
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
class ApplicationController < ActionController::Base
|
191
|
+
around_action :with_logtail_context
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
def with_logtail_context
|
196
|
+
if user_signed_in?
|
197
|
+
Logtail.with_context(user_context) { yield }
|
198
|
+
else
|
199
|
+
yield
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def user_context
|
204
|
+
Logtail::Contexts::User.new(
|
205
|
+
id: current_user.id,
|
206
|
+
name: current_user.name,
|
207
|
+
email: current_user.email
|
208
|
+
)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
```
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's
|
6
|
+
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class ExampleController < ApplicationController
|
2
|
+
# Index action
|
3
|
+
def index
|
4
|
+
send_logs_path = '/send_logs'
|
5
|
+
end
|
6
|
+
|
7
|
+
# The following action send example logs
|
8
|
+
def send_logs
|
9
|
+
# Sending logs using the Rails.logger
|
10
|
+
|
11
|
+
# Send debug logs messages using the debug() method
|
12
|
+
Rails.logger.debug("Hey! I am debuging!")
|
13
|
+
|
14
|
+
# Send informative messages about interesting events using the info() method
|
15
|
+
Rails.logger.info("You know what's interesting? Logtail !")
|
16
|
+
|
17
|
+
# Send messages about worrying events using the warn() method
|
18
|
+
Rails.logger.warn("Something might not be quite right...")
|
19
|
+
|
20
|
+
# Send error messages using the error() method
|
21
|
+
Rails.logger.error("Oops! Something went wrong.")
|
22
|
+
|
23
|
+
# Send messages about fatal events thet caused the app to crash using the fatal() method
|
24
|
+
Rails.logger.fatal("Application crashed! Needs to be fixed ASAP!")
|
25
|
+
|
26
|
+
|
27
|
+
# You can optionally add tags when logging
|
28
|
+
Rails.logger.tagged("tag1", "tag2").info("log message with tags")
|
29
|
+
|
30
|
+
|
31
|
+
# You can also provide additional information when logging
|
32
|
+
Rails.logger.warn("log structured data",
|
33
|
+
name: {
|
34
|
+
first: "John",
|
35
|
+
last: "Smith"
|
36
|
+
},
|
37
|
+
id: 123456
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// Import and register all your controllers from the importmap under controllers/*
|
2
|
+
|
3
|
+
import { application } from "controllers/application"
|
4
|
+
|
5
|
+
// Eager load all controllers defined in the import map under controllers/**/*_controller
|
6
|
+
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
|
7
|
+
eagerLoadControllersFrom("controllers", application)
|
8
|
+
|
9
|
+
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
|
10
|
+
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
|
11
|
+
// lazyLoadControllersFrom("controllers", application)
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>LogtailExampleProject</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
8
|
+
|
9
|
+
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|