logtail 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bb7693b6aa0c18cdfd743e711bbfb2a07d21e580e3698d9c361a4501aed76a8
4
- data.tar.gz: 48b28d5a283ce2fb97221dc9d940f4443ece4f576a6bfa8ddceb0fc8321233bb
3
+ metadata.gz: 4de48b70abbe9cebd9186345e9d410dd6021d53eaeaa9b204e10a364235e5088
4
+ data.tar.gz: df85920aa4c0f0c91b560816e4f57e4038bc7abf9035410264b134bad26ab9c7
5
5
  SHA512:
6
- metadata.gz: 646bc1896d44fa7704355a9426921a35eda9d34e0f80f8aaa7e35d91adc78fa51ab39fbde249b8835f6045720d6260b08c9687964072c9562dad4053720a9804
7
- data.tar.gz: a13480d4db23662178079edd858cf0ceb0fe33f90bdfc5acb178aadc2187e5ee5634b58ac7c5cc6a7c14fcbd367b32f58fa187d9687e22a0741a02ff9121791a
6
+ metadata.gz: 3edf710be0595d057760e455787ee3b457a84d6e1ac998785a89f06693e05a33cf2c5b7043d133c6e61da732ea0c05a96f11990749455f118c6ca2c80ae19440
7
+ data.tar.gz: 296e2a96d9f98c4bd11e9f3148524a902104b8fd3d2f0b2ed1482033f2aadf87516093356b1cbf671e3f07c32fd41b7f1ab430d8db648d4e9e06eb2a4e839568
data/CHANGELOG.md CHANGED
@@ -22,3 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
22
22
  ## [0.1.7] - 2021-08-16
23
23
 
24
24
  - Fixed runtime context's frame label encoding.
25
+
26
+ ## [0.1.8] - 2023-01-16
27
+
28
+ - Fix issue where message is lost when logging hashes with multiple IO devices (thanks @olivier-thatch!)
data/README.md CHANGED
@@ -1,4 +1,69 @@
1
- # 🪵 Logtail - Ruby Logging For Everyone
1
+ # Logtail - Ruby 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/workflows/build/badge.svg)](https://github.com/logtail/logtail-ruby/actions?query=workflow%3Abuild)
8
+
9
+ Collect logs directly from your Ruby projects. To start logging Ruby on Rails projects explore the [Logtail Rails library](https://github.com/logtail/logtail-ruby-rails).
10
+
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://docs.logtail.com/).
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
+
22
+ # Installation
23
+ Install the Logtail Ruby client library, run the following command:
24
+
25
+ ```bash
26
+ bundle add logtail
27
+ ```
28
+
29
+ This will install Logtail gem and create `Gemfile` and `Gemfile.lock` that are used to track the code dependencies.
30
+
31
+ Alternatively, add `gem "logtail"` to your `Gemfile` manually and then run `bundle install`.
32
+
33
+ ---
34
+
35
+ # Example project
36
+
37
+ To help you get started with using Logtail in your Ruby projects, we have prepared a simple program that showcases the usage of Logtail logger.
38
+
39
+ ## Download and install the example project
40
+
41
+ You can download the [example project](https://github.com/logtail/logtail-ruby/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:
42
+
43
+ ```bash
44
+ bundle install
45
+ ```
46
+
47
+ This will install all dependencies listed in the `Gemfile.lock` file.
48
+
49
+ ## Run the example project
50
+
51
+ To run the example application, run the following command:
52
+
53
+ ```bash
54
+ ruby main.rb <source-token>
55
+ ```
56
+
57
+ *Don't forget to replace `<source-token>` with your actual source token which you can find by going to logtail.com -> sources -> edit.*
58
+
59
+ This will create a total of 5 different logs, each corresponding to a different log level. You can review these logs in Logtail.
60
+
61
+ ## Explore how example project works
62
+
63
+ Learn how to setup Ruby logging by exploring the workings of the [example project](https://github.com/logtail/logtail-ruby/tree/main/example-project) in detail.
64
+
65
+ ---
66
+
67
+ ## Get in touch
68
+
69
+ Have any questions? Please explore the Logtail [documentation](https://docs.logtail.com/) or contact our [support](https://betterstack.com/help).
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem "logtail"
@@ -0,0 +1,15 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ logtail (0.1.7)
5
+ msgpack (~> 1.0)
6
+ msgpack (1.4.4)
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ logtail
13
+
14
+ BUNDLED WITH
15
+ 2.1.4
@@ -0,0 +1,201 @@
1
+ # Example project
2
+
3
+ To help you get started with using Logtail in your Ruby projects, we have prepared a simple program that showcases the usage of Logtail logger.
4
+
5
+ ## Download and install the example project
6
+
7
+ 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:
8
+
9
+ ```bash
10
+ bundle install
11
+ ```
12
+
13
+ This will install all dependencies listed in the `Gemfile.lock` file.
14
+
15
+ Alternatively, add `gem "logtail"` to your `Gemfile` manually and then run `bundle install`.
16
+
17
+ ## Run the example project
18
+
19
+ Replace `<source-token>` with your actual source token in the `main.rb` file. You can find your source token by going to _logtail.com -> sources -> edit_.
20
+
21
+ To run the example application, run the following command adding your source token:
22
+
23
+ ```bash
24
+ ruby main.rb <source-token>
25
+ ```
26
+
27
+ This will create a total of 5 different logs, each corresponding to a different log level. You can review these logs in Logtail.
28
+
29
+ # Logging
30
+
31
+ The `logger` instance we created in the installation section is used to send log messages to Logtail. It provides 5 logging methods for the 5 default log levels. The log levels and their method are:
32
+
33
+ - **DEBUG** - Send debug messages using the `debug()` method
34
+ - **INFO** - Send informative messages about the application progress using the `info()` method
35
+ - **WARN** - Report non-critical issues using the `warn()` method
36
+ - **ERROR** - Send messages about serious problems using the `error()` method
37
+ - **FATAL** - Send messages about fatal events that caused the app to crash using the `fatal()` method
38
+
39
+ ## Logging example
40
+
41
+ In this example, we will send two logs - **DEBUG** and **INFO**
42
+
43
+ ```ruby
44
+ # Send debug logs messages using the debug() method
45
+ logger.debug("Logtail is ready!")
46
+
47
+ # Send informative messages about interesting events using the info() method
48
+ logger.info("I am using Logtail!")
49
+ ```
50
+
51
+ This will create the following output:
52
+
53
+ ```json
54
+ {
55
+ "dt": "2021-03-29T11:24:54.788Z",
56
+ "level": "debug",
57
+ "message": "Logtail is ready!",
58
+ "context": {
59
+ "runtime": {
60
+ "thread_id": 123,
61
+ "file": "main.rb",
62
+ "line": 6,
63
+ "frame": null,
64
+ "frame_label": "<main>"
65
+ },
66
+ "system": {
67
+ "hostname": "hostname"
68
+ "pid": 1234
69
+ }
70
+ }
71
+ }
72
+
73
+ {
74
+ "dt": "2021-03-29T11:24:54.788Z",
75
+ "level": "info",
76
+ "message": "I am using Logtail!",
77
+ "context": {
78
+ "runtime": {
79
+ "thread_id": 123,
80
+ "file": "main.rb",
81
+ "line": 6,
82
+ "frame": null,
83
+ "frame_label": "<main>"
84
+ },
85
+ "system": {
86
+ "hostname": "hostname"
87
+ "pid": 1234
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ ## Log structured data
94
+
95
+ 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.
96
+
97
+ ```ruby
98
+ # Send messages about worrying events using the warn() method
99
+ # You can also log additional structured data
100
+ logger.warn(
101
+ "log structured data",
102
+ item: {
103
+ url: "https://fictional-store.com/item-123",
104
+ price: 100.00
105
+ }
106
+ )
107
+ ```
108
+
109
+ This will create the following output:
110
+
111
+ ```json
112
+ {
113
+ "dt": "2021-03-29T11:24:54.788Z",
114
+ "level": "warn",
115
+ "message": "log structured data",
116
+ "item": {
117
+ "url": "https://fictional-store.com/item-123",
118
+ "price": 100.00
119
+ },
120
+ "context": {
121
+ "runtime": {
122
+ "thread_id": 123,
123
+ "file": "main.rb",
124
+ "line": 7,
125
+ "frame": null,
126
+ "frame_label": "<main>"
127
+ },
128
+ "system": {
129
+ "hostname": "hostname"
130
+ "pid": 1234
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ ## Context
137
+
138
+ We add information about the current runtime environment and the current process into a `context` field of the logged item by default.
139
+
140
+ 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:
141
+
142
+ ```ruby
143
+ # Provide context to the logs
144
+ Logtail.with_context(user: { id: 123 }) do
145
+ logger.info('new subscription')
146
+ end
147
+ ```
148
+
149
+ This will generate the following JSON output:
150
+
151
+ ```json
152
+ {
153
+ "dt": "2021-03-29T11:24:54.788Z",
154
+ "level": "warn",
155
+ "message": "new subscription",
156
+ "context": {
157
+ "runtime": {
158
+ "thread_id": 123456,
159
+ "file": "main.rb",
160
+ "line": 2,
161
+ "frame": null,
162
+ "frame_label": "<main>"
163
+ },
164
+ "system": {
165
+ "hostname": "hostname"
166
+ "pid": 1234
167
+ },
168
+ "user": {
169
+ "id": 123
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ We will automatically add the information about the current user to each log if you're using Ruby on Rails and the Devise gem.
176
+
177
+ 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:
178
+
179
+ ```ruby
180
+ class ApplicationController < ActionController::Base
181
+ around_action :with_logtail_context
182
+
183
+ private
184
+
185
+ def with_logtail_context
186
+ if user_signed_in?
187
+ Logtail.with_context(user_context) { yield }
188
+ else
189
+ yield
190
+ end
191
+ end
192
+
193
+ def user_context
194
+ Logtail::Contexts::User.new(
195
+ id: current_user.id,
196
+ name: current_user.name,
197
+ email: current_user.email
198
+ )
199
+ end
200
+ end
201
+ ```
@@ -0,0 +1,42 @@
1
+ # This file showcases usage of logtail on Ruby projects
2
+ # For more information visit https://github.com/logtail/logtail-ruby
3
+
4
+ # SETUP
5
+
6
+ # Include logtail library
7
+ require "logtail"
8
+
9
+ # Check for program arguments
10
+ if ARGV.length != 1
11
+ puts "Program needs source token to run. Run the program as followed\nruby main.rb <source-token>"
12
+ exit
13
+ end
14
+ # Create logger
15
+ http_device = Logtail::LogDevices::HTTP.new(ARGV[0])
16
+ logger = Logtail::Logger.new(http_device)
17
+
18
+ # LOGGING
19
+
20
+ # Send debug logs messages using the debug() method
21
+ logger.debug("Logtail is ready!")
22
+
23
+ # Send informative messages about interesting events using the info() method
24
+ logger.info("I am using Logtail!")
25
+
26
+ # Send messages about worrying events using the warn() method
27
+ # You can also log additional structured data
28
+ logger.warn(
29
+ "log structured data",
30
+ item: {
31
+ url: "https://fictional-store.com/item-123",
32
+ price: 100.00
33
+ }
34
+ )
35
+
36
+ # Send error messages using the error() method
37
+ logger.error("Oops! An error occurred!")
38
+
39
+ # Send messages about fatal events that caused the app to crash using the fatal() method
40
+ logger.fatal("Application crash! Needs to be fixed ASP!")
41
+
42
+ puts "All done! You can check your logs now."
@@ -41,11 +41,13 @@ module Logtail
41
41
  tags: tags)
42
42
  elsif logged_obj.is_a?(Hash)
43
43
  # Extract the tags
44
- tags.push(logged_obj.delete(:tag)) if logged_obj.key?(:tag)
45
- tags.concat(logged_obj.delete(:tags)) if logged_obj.key?(:tags)
44
+ tags.push(logged_obj[:tag]) if logged_obj.key?(:tag)
45
+ tags.concat(logged_obj[:tags]) if logged_obj.key?(:tags)
46
46
  tags.uniq!
47
47
 
48
- message = logged_obj.delete(:message)
48
+ message = logged_obj[:message]
49
+
50
+ logged_obj = logged_obj.select { |k, _| ![:message, :tag, :tags].include?(k) }
49
51
 
50
52
  LogEntry.new(level, time, progname, message, context_snapshot, logged_obj, tags: tags)
51
53
  else
@@ -1,3 +1,3 @@
1
1
  module Logtail
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -78,6 +78,16 @@ describe Logtail::Logger do
78
78
  expect(io.string).to eq("")
79
79
  end
80
80
 
81
+ it "should not lose message when logging hashes with multiple io devices" do
82
+ io1 = StringIO.new
83
+ io2 = StringIO.new
84
+ logger = Logtail::Logger.new(io1, io2)
85
+ message = {message: "payment rejected", payment_rejected: {customer_id: "abcde1234", amount: 100}}
86
+ logger.info(message)
87
+ expect(io1.string).to include("payment rejected")
88
+ expect(io2.string).to include("payment rejected")
89
+ end
90
+
81
91
  context "with the AugmentedFormatter" do
82
92
  before(:each) { logger.formatter = Logtail::Logger::AugmentedFormatter.new }
83
93
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logtail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-16 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -151,6 +151,10 @@ files:
151
151
  - LICENSE.md
152
152
  - README.md
153
153
  - Rakefile
154
+ - example-project/Gemfile
155
+ - example-project/Gemfile.lock
156
+ - example-project/README.md
157
+ - example-project/main.rb
154
158
  - lib/logtail.rb
155
159
  - lib/logtail/config.rb
156
160
  - lib/logtail/config/integrations.rb
@@ -219,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
223
  - !ruby/object:Gem::Version
220
224
  version: '0'
221
225
  requirements: []
222
- rubygems_version: 3.2.3
226
+ rubygems_version: 3.3.7
223
227
  signing_key:
224
228
  specification_version: 4
225
229
  summary: Query logs like you query your database. https://logtail.com