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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c56751e0f6bd6c2b7fbd83d1affe843efb301c079c0f34fa9266a136b7075cac
4
- data.tar.gz: 38ab5f1ad84e30db98076365905cbc8f57d9d1a132458d4aad671a3fadfed2f1
3
+ metadata.gz: 2855adaa624e1c11f210324472a218eeb545b4bc56aaaf3719c3b98e05fe4e91
4
+ data.tar.gz: fdc4f20a9d532c007b0b322e81dac15efe4d8f70e17feefe12b6e9459db8fd8c
5
5
  SHA512:
6
- metadata.gz: 1888b328208392bfe29c03105b8e1e84dc06828f047ff4fa2b388cb90c55fc0da145ef0f5d996412d87e5f570ed75d559e3e9f5c3f2fb7c48a15bd766544dd62
7
- data.tar.gz: db3dc693415a8b549c06aa5f5aa41404c05ace86df14320472f439085b2f47fd6cbaa0cf3f5f19f9e7a4701ee0e5702aa880ce5ee5928f29a4bf00a2fec203d4
6
+ metadata.gz: cc7c4215bcfdbd1bab12781d4fa8d3e435be223dd320e2eac75b99c9503934d0be50d53d00e08c00f9d3ad8d7fc066cd3be1fc83ec1241e24f2d76b155637ce0
7
+ data.tar.gz: a9285d3a1b32d9b9bb97efe5174c5c1729842d7598be83606f48a644a53615642dba4a4bbbb9e396f5904ed9120e7d58f6f54de7784fb53845b80f94b870a1b0
data/README.md CHANGED
@@ -1,43 +1,113 @@
1
1
  # Supalog
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/supalog.svg)](https://rubygems.org/gems/supalog)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/supalog`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem "supalog"
16
+ ```
10
17
 
11
- Install the gem and add to the application's Gemfile by executing:
18
+ Then execute:
12
19
 
13
20
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ bundle install
15
22
  ```
16
23
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
24
+ Or install it yourself:
18
25
 
19
26
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- ## Usage
65
+ ### Per-Environment Usage
66
+
67
+ Use `enabled` to control which environments ship logs:
24
68
 
25
- TODO: Write usage instructions here
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 at https://github.com/[USERNAME]/supalog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/supalog/blob/master/CODE_OF_CONDUCT.md).
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
@@ -4,8 +4,8 @@ require_relative "log_subscriber"
4
4
 
5
5
  module Supalog
6
6
  class Railtie < Rails::Railtie
7
- initializer "supalog.configure_logging" do
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Supalog
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Jeon