sensible_logging 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: 573a3b8040fec85373dc5f2a00a82655e51ebe08d28b31c1a4dbfa3f18b0147f
4
- data.tar.gz: 4d7d894842e36853317062862cd99577d9f61b78ad73fbbe909315ff14f8ecd6
3
+ metadata.gz: 64e20e7d13d4881981be87fa54a55d5dd4341a4c2fb3d6288f2ad68a35c1f096
4
+ data.tar.gz: 07a666fe48011d6c8b76b173161613973fe34bbfaf0994c15a06481744236829
5
5
  SHA512:
6
- metadata.gz: a8dea52bb2451b3bdcdce68b1ff75f5cfaa385b2321d9027b687f5b8bd27c5cef56d68fa197081a79cc0b4c11303e706867ad3ba6dd3ddba07c2f89b0a3f5004
7
- data.tar.gz: 6b1ebcc33d6b13a5e4ce19307d538f4387ccfbd0e5cf5dcbc45d4729786e7ea2f41f917e80bed39d8c4b7aadf521aacb60e49061a23737581d23cfe907baac44
6
+ metadata.gz: 9e7645eb34a56cfc7f8187c894a7195a9ec60a469c2efe3da221f3e176149a1164a175c433821222cfe8f2294b4c79abd036b759dfb1ceb8155fc6c10d25c4c7
7
+ data.tar.gz: 62b656360bed805e943fa1b0c8b6ca5614d0c7af8e4caa447ade4f067b8b6f62fef5905faf9dc33f1e5219d2a2bd994020d48dabb9b506b8351b458fbc7f0016
File without changes
@@ -1,7 +1,7 @@
1
1
  #\ --quiet
2
2
  require 'logger'
3
- require './app'
4
- require './lib/sensible_logging'
3
+ require_relative './app'
4
+ require_relative '../lib/sensible_logging'
5
5
 
6
6
  run sensible_logging(
7
7
  app: App,
@@ -0,0 +1,22 @@
1
+ class SubdomainParser
2
+ attr_reader :tld_length
3
+
4
+ def initialize(tld_length: 1)
5
+ @tld_length = tld_length
6
+ end
7
+
8
+ def parse(host)
9
+ domain_parts = host.split('.')
10
+
11
+ return domain_parts[0] if domain_parts.size == 1
12
+
13
+ main_domain_length = tld_length + 1
14
+ subdomain_length = domain_parts.size - main_domain_length
15
+
16
+ subdomain_parts = domain_parts[0...subdomain_length]
17
+
18
+ return nil if subdomain_parts.size < 1
19
+
20
+ subdomain_parts.join('.')
21
+ end
22
+ end
@@ -1,4 +1,5 @@
1
1
  require 'active_support/tagged_logging'
2
+ require_relative '../helpers/subdomain_parser'
2
3
 
3
4
  class TaggedLogger
4
5
  def initialize(app, logger = Logger.new(STDOUT), tags = [], tld_length = 1)
@@ -6,9 +7,7 @@ class TaggedLogger
6
7
  @logger = ActiveSupport::TaggedLogging.new(logger)
7
8
 
8
9
  @tags = tags
9
- @tags = default_tags if tags.empty?
10
-
11
- @tld_length = tld_length
10
+ @tags = self.class.default_tags(tld_length: tld_length) if tags.empty?
12
11
  end
13
12
 
14
13
  def call(env)
@@ -18,23 +17,17 @@ class TaggedLogger
18
17
  end
19
18
  end
20
19
 
21
- def default_tags
20
+ def self.default_tags(tld_length: 1)
22
21
  [lambda { |req|
23
- [subdomain(req), ENV['RACK_ENV'], req.env['request_id']]
22
+ subdomain_parser = SubdomainParser.new(tld_length: tld_length)
23
+ subdomain = subdomain_parser.parse(req.host)
24
+
25
+ [subdomain || 'n/a', ENV['RACK_ENV'], req.env['request_id']]
24
26
  }]
25
27
  end
26
28
 
27
29
  private
28
30
 
29
- def subdomain(req)
30
- domain_parts = req.host.split('.')
31
-
32
- main_domain_length = @tld_length + 1
33
- subdomain_length = domain_parts.length - main_domain_length
34
-
35
- domain_parts[0...subdomain_length].join('.')
36
- end
37
-
38
31
  def generate_tags(env)
39
32
  req = Rack::Request.new(env)
40
33
  tags = @tags.map do |tag|
@@ -1,3 +1,3 @@
1
1
  module SensibleLogging
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensible_logging
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
  - David Winter
@@ -137,9 +137,10 @@ files:
137
137
  - LICENSE.txt
138
138
  - README.md
139
139
  - Rakefile
140
- - app.rb
141
- - config.ru
140
+ - examples/app.rb
141
+ - examples/config.ru
142
142
  - lib/sensible_logging.rb
143
+ - lib/sensible_logging/helpers/subdomain_parser.rb
143
144
  - lib/sensible_logging/middlewares/request_id.rb
144
145
  - lib/sensible_logging/middlewares/request_logger.rb
145
146
  - lib/sensible_logging/middlewares/tagged_logger.rb