supalog 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +86 -16
- data/lib/supalog/configuration.rb +2 -1
- data/lib/supalog/railtie.rb +2 -2
- data/lib/supalog/version.rb +1 -1
- data/lib/supalog.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2855adaa624e1c11f210324472a218eeb545b4bc56aaaf3719c3b98e05fe4e91
|
|
4
|
+
data.tar.gz: fdc4f20a9d532c007b0b322e81dac15efe4d8f70e17feefe12b6e9459db8fd8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc7c4215bcfdbd1bab12781d4fa8d3e435be223dd320e2eac75b99c9503934d0be50d53d00e08c00f9d3ad8d7fc066cd3be1fc83ec1241e24f2d76b155637ce0
|
|
7
|
+
data.tar.gz: a9285d3a1b32d9b9bb97efe5174c5c1729842d7598be83606f48a644a53615642dba4a4bbbb9e396f5904ed9120e7d58f6f54de7784fb53845b80f94b870a1b0
|
data/README.md
CHANGED
|
@@ -1,43 +1,113 @@
|
|
|
1
1
|
# Supalog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://rubygems.org/gems/supalog)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Ship your Rails logs to [Supalog](https://www.supalog.dev) with zero external dependencies.
|
|
7
|
+
|
|
8
|
+
Supalog is a drop-in Rails logger that buffers log entries in memory and flushes them in batches to the Supalog ingest API via a background thread. Your existing Rails logging continues to work as normal — Supalog simply taps into it.
|
|
6
9
|
|
|
7
10
|
## Installation
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem "supalog"
|
|
16
|
+
```
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
Then execute:
|
|
12
19
|
|
|
13
20
|
```bash
|
|
14
|
-
bundle
|
|
21
|
+
bundle install
|
|
15
22
|
```
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
Or install it yourself:
|
|
18
25
|
|
|
19
26
|
```bash
|
|
20
|
-
gem install
|
|
27
|
+
gem install supalog
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
1. Get your API key from [supalog.dev](https://www.supalog.dev)
|
|
33
|
+
|
|
34
|
+
2. Create an initializer:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
# config/initializers/supalog.rb
|
|
38
|
+
Supalog.configure do |config|
|
|
39
|
+
config.api_key = ENV["SUPALOG_API_KEY"]
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That's it. Your Rails logs now flow to Supalog automatically — no other code changes needed.
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
| Option | Default | Description |
|
|
48
|
+
|------------------|------------------------------|------------------------------------------------------|
|
|
49
|
+
| `api_key` | `nil` | **Required.** Your Supalog project API key. |
|
|
50
|
+
| `url` | `"https://www.supalog.dev"` | Supalog ingest endpoint. |
|
|
51
|
+
| `flush_interval` | `5` | Seconds between background flushes. |
|
|
52
|
+
| `batch_size` | `100` | Max entries buffered before an immediate flush. |
|
|
53
|
+
| `enabled` | `true` | Enable or disable log shipping. |
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
Supalog.configure do |config|
|
|
57
|
+
config.api_key = ENV["SUPALOG_API_KEY"]
|
|
58
|
+
config.url = "https://www.supalog.dev" # default
|
|
59
|
+
config.flush_interval = 5 # seconds, default
|
|
60
|
+
config.batch_size = 100 # default
|
|
61
|
+
config.enabled = true # default
|
|
62
|
+
end
|
|
21
63
|
```
|
|
22
64
|
|
|
23
|
-
|
|
65
|
+
### Per-Environment Usage
|
|
66
|
+
|
|
67
|
+
Use `enabled` to control which environments ship logs:
|
|
24
68
|
|
|
25
|
-
|
|
69
|
+
```ruby
|
|
70
|
+
Supalog.configure do |config|
|
|
71
|
+
config.api_key = ENV["SUPALOG_API_KEY"]
|
|
72
|
+
config.enabled = Rails.env.production? || Rails.env.staging?
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
When `enabled` is `false`, no background thread is started and log entries are silently discarded.
|
|
77
|
+
|
|
78
|
+
## How It Works
|
|
79
|
+
|
|
80
|
+
1. **Intercepts** — Wraps `Rails.logger` to capture every log call.
|
|
81
|
+
2. **Buffers** — Stores entries in a thread-safe in-memory array.
|
|
82
|
+
3. **Flushes** — A background thread sends batches to the Supalog API every `flush_interval` seconds, or immediately when `batch_size` is reached.
|
|
83
|
+
4. **Passes through** — All logs still go to the original Rails logger, so your existing output (console, file, etc.) is unaffected.
|
|
84
|
+
5. **Shuts down gracefully** — Remaining buffered logs are flushed on process exit via `at_exit`.
|
|
85
|
+
|
|
86
|
+
Supalog never raises exceptions that could crash your application. Transport errors are silently logged to `STDERR`.
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
89
|
+
|
|
90
|
+
- Ruby >= 3.0
|
|
91
|
+
- Rails (auto-configures via Railtie)
|
|
92
|
+
- **Zero external dependencies** — uses only Ruby stdlib (`net/http`, `json`, `uri`)
|
|
26
93
|
|
|
27
94
|
## Development
|
|
28
95
|
|
|
29
|
-
|
|
96
|
+
```bash
|
|
97
|
+
# Run the test suite
|
|
98
|
+
bundle exec rspec
|
|
99
|
+
|
|
100
|
+
# Build the gem locally
|
|
101
|
+
bundle exec rake build
|
|
30
102
|
|
|
31
|
-
|
|
103
|
+
# Install the gem locally
|
|
104
|
+
bundle exec rake install
|
|
105
|
+
```
|
|
32
106
|
|
|
33
107
|
## Contributing
|
|
34
108
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub
|
|
109
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/chrisjeon/supalog-rb).
|
|
36
110
|
|
|
37
111
|
## License
|
|
38
112
|
|
|
39
113
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
-
|
|
41
|
-
## Code of Conduct
|
|
42
|
-
|
|
43
|
-
Everyone interacting in the Supalog project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/supalog/blob/master/CODE_OF_CONDUCT.md).
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
module Supalog
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor :api_key, :url, :batch_size, :flush_interval
|
|
5
|
+
attr_accessor :api_key, :url, :batch_size, :flush_interval, :enabled
|
|
6
6
|
|
|
7
7
|
def initialize
|
|
8
8
|
@api_key = nil
|
|
9
9
|
@url = "https://www.supalog.dev"
|
|
10
10
|
@batch_size = 100
|
|
11
11
|
@flush_interval = 5
|
|
12
|
+
@enabled = true
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
end
|
data/lib/supalog/railtie.rb
CHANGED
|
@@ -4,8 +4,8 @@ require_relative "log_subscriber"
|
|
|
4
4
|
|
|
5
5
|
module Supalog
|
|
6
6
|
class Railtie < Rails::Railtie
|
|
7
|
-
|
|
8
|
-
if Supalog.configuration.api_key
|
|
7
|
+
config.after_initialize do
|
|
8
|
+
if Supalog.configuration.api_key && Supalog.enabled?
|
|
9
9
|
Supalog.start!
|
|
10
10
|
Supalog::LogSubscriber.attach_logger!(Rails.logger)
|
|
11
11
|
end
|
data/lib/supalog/version.rb
CHANGED
data/lib/supalog.rb
CHANGED
|
@@ -18,8 +18,13 @@ module Supalog
|
|
|
18
18
|
start!
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def enabled?
|
|
22
|
+
configuration.enabled
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
def start!
|
|
22
26
|
return if @started
|
|
27
|
+
return unless enabled?
|
|
23
28
|
|
|
24
29
|
@buffer = Buffer.new(
|
|
25
30
|
batch_size: configuration.batch_size,
|
|
@@ -35,6 +40,8 @@ module Supalog
|
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
def push(entry)
|
|
43
|
+
return unless enabled?
|
|
44
|
+
|
|
38
45
|
@buffer&.push(entry)
|
|
39
46
|
end
|
|
40
47
|
|