api_hit_logger 0.1.0 → 0.2.0

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: 0b5a91ee46006e34989796e757e296e3cb2740f927ed51facfe4f71996055029
4
- data.tar.gz: 2138600bb5b88fe56ffe747123616e4eba75932176f6c1aeaa189b125c5ba9a6
3
+ metadata.gz: b97f560d9dbce9d608affa66d0211324b3789e801448436dbef9636840ea42f9
4
+ data.tar.gz: 8580dbded8673fc96618d6771e46bccbb9a9d67de6b32a0e5d09d6bf5f82924b
5
5
  SHA512:
6
- metadata.gz: 20e66a1bcf7e099c7e7e0d6d36b98fdb5c0ba81776b666a2413442fc7ae7f3ef481609d1c1be700cb67537a7300724eaf6085c219cf0f2b0a41c22d2e2ffadf1
7
- data.tar.gz: a4fd6c439b3089d04a8c49e4c0df3ed1a048190adc2be5f9e6881b9344d83e7e0e28797a0a76ac7d26cf5ce95146cf453339c9275a4a8a22c35367d643dd6e82
6
+ metadata.gz: 19865985c155a97829f75a56465ad558e1ce7407b9d84f90d494a41ae9bb2492d1be2caa737126588f6e5247658a2dce0d2c0eb2c1bfde89d35b743a60da4c9e
7
+ data.tar.gz: 2825f80ce6d8b8ebd511f3687d3531dca32514a59e9af1a5eff7cd7eb42a7a5adaa78ac3d693ab08f9c63db44c9bc91af15a00ba6461bb6d7bad10ca98b9d7e4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.2.0] - 2025-06-25
2
+
3
+ ### Added
4
+ - Support for JSON log format via configuration
5
+ - New `ApiHitLogger.configure` block
6
+ - Manual initializer support for customizing format, whitelist/blacklist, and log directory
7
+
1
8
  ## [Unreleased]
2
9
 
3
10
  ## [0.1.0] - 2025-06-19
data/README.md CHANGED
@@ -27,7 +27,7 @@ require 'api_hit_logger'
27
27
  2. Add the middleware
28
28
 
29
29
  For Rails:
30
- # config/application.rb
30
+ config/application.rb
31
31
  config.middleware.use ApiHitLogger::Middleware
32
32
 
33
33
  For Rack apps, update your config.ru:
@@ -41,7 +41,22 @@ Log File Location
41
41
  The logs are written to:
42
42
  log/api_hit_logs_YYYY-MM-DD.csv
43
43
 
44
- Each day's requests are stored in their own CSV file.
44
+ Each day's requests are stored in their own CSV/JSON file.
45
+
46
+ ## Configuration
47
+
48
+ To customize how API hits are logged, create a file at:
49
+
50
+
51
+ With the following content:
52
+
53
+ ```ruby
54
+ ApiHitLogger.configure do |config|
55
+ # Format options: :csv, :json (default: :csv)
56
+ config.log_format = :csv
57
+ end
58
+
59
+ If no initializer is present, default settings will be used.
45
60
 
46
61
  ## Development
47
62
 
@@ -43,7 +43,12 @@ end
43
43
  end
44
44
 
45
45
  def log_api_hit(request, status, start_time, end_time, error: nil)
46
- CsvLogger.log(
46
+ logger_class = case ApiHitLogger.configuration&.log_format
47
+ when :json then ApiHitLogger::JsonLogger
48
+ else ApiHitLogger::CsvLogger
49
+ end
50
+
51
+ logger_class.log(
47
52
  request: request,
48
53
  status: status,
49
54
  start_time: start_time,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiHitLogger
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,7 +1,17 @@
1
- require_relative "api_hit_logger/version"
2
- require "api_hit_logger/middleware"
3
-
4
- module ApiHitLogger
5
- class Error < StandardError; end
6
-
7
- end
1
+ require_relative "api_hit_logger/version"
2
+ require "api_hit_logger/middleware"
3
+ require "api_hit_logger/configuration"
4
+ require "csv_logger"
5
+ require "api_hit_logger/json_logger"
6
+
7
+ module ApiHitLogger
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration)
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_hit_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChaitanyaGalande
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-23 00:00:00.000000000 Z
10
+ date: 2025-06-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: csv
@@ -38,7 +38,7 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  description: Rack middleware that logs API request details (method, path, IP, duration,
41
- status, errors) into a CSV file, with daily file rotation
41
+ status, errors) into a CSV or JSON file. Supports daily rotation and format customization.
42
42
  email:
43
43
  - chaitany.galande@gmail.com
44
44
  executables: []
@@ -61,9 +61,10 @@ homepage: https://github.com/chaitanyag1-c/api_hit_logger
61
61
  licenses:
62
62
  - MIT
63
63
  metadata:
64
+ allowed_push_host: https://rubygems.org
64
65
  homepage_uri: https://github.com/chaitanyag1-c/api_hit_logger
65
66
  source_code_uri: https://github.com/chaitanyag1-c/api_hit_logger
66
- changelog_uri: https://github.com/chaitanyag1-c/api_hit_logger
67
+ changelog_uri: https://github.com/chaitanyag1-c/api_hit_logger/blob/main/README.md
67
68
  rdoc_options: []
68
69
  require_paths:
69
70
  - lib
@@ -80,5 +81,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements: []
81
82
  rubygems_version: 3.6.1
82
83
  specification_version: 4
83
- summary: Logs API requests to a CSV file with daily rotation
84
+ summary: Logs API requests to a CSV or JSON file with daily rotation
84
85
  test_files: []