outland-tag_runes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07f173cc03377ce577805642a9058df35d55d63d
4
+ data.tar.gz: 31c96cfa3adf59b23b271d3d1ae06f8a6154dcaa
5
+ SHA512:
6
+ metadata.gz: 80e124536d45bf3e1b9a13b99aaf7ec64022db8b415267c80bade563687ef9cf422baabea42a669c871d54ad3d2467ac4b6bce04dfb1894f4ee1349682714379
7
+ data.tar.gz: 6e230cf59991beea4197db2b3f086890c465190a62e7661a71c5787837ef5e82339988bd9fc12e743ff77a7db928611d5e7923067c806e8b932d8a93aa007df3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ **1.0** (February 27, 2017)
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in outland-tag_runes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Outland Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Outland::TagRunes
2
+
3
+ The Outland TagRunes gem adds unicode glyphs to the Rails logger output that encode the session and
4
+ request id in a way that occupies a minimum of visual space but provides very useful debugging
5
+ capabilities.
6
+
7
+ For example, it is easy to grep for a single session's log output, or the log output for a complete
8
+ request, even if many requests are interleaved into the same log file.
9
+
10
+ Beyond the debugging capabilities, TagRunes tries to keep the log file output pleasant to work
11
+ with by only occupying 10 columns of text. It uses unicode to encode a full byte of data into each
12
+ column position in a visually clear way.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'outland-tag_runes'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install outland-tag_runes
29
+
30
+ ## Usage
31
+
32
+ In your initialization, add:
33
+
34
+ config.log_tags = [ Outland::TagRunes.rails_tag ]
35
+
36
+ Your log output will look something like the following.
37
+
38
+ [★¿xÄ ϱm] Completed 200 OK in 78ms (Views: 0.7ms | ActiveRecord: 72.6ms)
39
+
40
+ The format is:
41
+
42
+ [<encoded session id> <encoded request id>]
43
+
44
+ So to look at a user's complete session log output, do the following:
45
+
46
+ grep "<encoded session id>" production.log
47
+
48
+ Or for a particular request:
49
+
50
+ grep "<encoded request id>" production.log
51
+
52
+ The tag is added to the Rack environment, so tools like Airbrake will contain it in
53
+ their exception environment information. You can therefore look at a recorded exception
54
+ and quickly produce the entire log output for that request.
55
+
56
+ The gem also wraps the standard Rails log formatter so that multiline log messages will be
57
+ tagged properly on each line.
58
+
59
+ The glyphs were chosen for legibility in OSX terminal fonts.
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/outland/tag_runes.
70
+
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
75
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "outland/tag_runes"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ module Outland
2
+ module TagRunes
3
+
4
+ VERSION = "1.0.0"
5
+
6
+ end
7
+ end
@@ -0,0 +1,82 @@
1
+ require 'outland/tag_runes/version'
2
+
3
+ module Outland
4
+ module TagRunes
5
+
6
+ # These glyphs should be chosen to maximize visual distinctiveness
7
+ # while being available in terminal fonts.
8
+
9
+ GLYPHS = %w(
10
+ a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5
11
+ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 6 7 8 9 ᚠ ÿ
12
+ À Á ᚢ Ã Ä Å Æ Ç È ᚣ Ê Ë Ì Í Î Ï Ð Ñ Ò Ó ᚧ Õ Ö × Ø Ù Ú Û Ü ᛗ ᚸ ᛉ
13
+ Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü
14
+ ΐ § ¶ Γ Δ © ® ¥ Θ £ ¿ Λ « » Ξ ± Π ¤ Σ ¢ ¡ Φ ° Ψ Ω Ϊ Ϋ ά έ ή ί ΰ
15
+ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ ϐ ϑ
16
+ ϒ ϓ ϔ ϕ ϖ ϗ Ϙ ϙ Ϛ ϛ Ϝ ϝ Ϟ ϟ Ϡ ϡ Ϣ ϣ Ϥ ϥ Ϧ ϧ Ϩ ϩ Ϫ ϫ Ϭ ϭ Ϯ ϯ ϰ ϱ
17
+ ♥ Б ♦ ♠ Д ♣ Ж ★ И Й ☉ Л ☇ ☈ ☃ П ☂ ☀ ᛉ ☆ Ф ᛰ Ц Ч Ш Щ Ъ Ы ☥ Э Ю Я
18
+ )
19
+
20
+
21
+ def self.sign(hex)
22
+ hex.scan(/\h\h/).map do |b|
23
+ GLYPHS[b.to_i(16)]
24
+ end.join
25
+ end
26
+
27
+ def self.signature(sid, rid)
28
+ "#{sid ? sign(sid[0,8]) : '____'} #{sign(rid[0,4])}"
29
+ end
30
+
31
+ # At this point in the middleware, we don't have access to the session.
32
+ # A good approximation is the passed-up session id, although it's
33
+ # controlled by the client. We 'sign' it with a compressed visual
34
+ # representation that doesn't clutter up the log too badly and is still
35
+ # highly likely to be unique when used for debugging expeditions into
36
+ # the log.
37
+ #
38
+ # An abbreviated signature of the request id is added as well, to aid
39
+ # in understanding interleaved log entries.
40
+
41
+ def self.rails_tag
42
+ Proc.new do |req|
43
+ # Set the tag in the rack environment so it can be picked up by
44
+ # tools like Airbrake.
45
+ sess_id = req.cookies[Rails.application.config.session_options[:key]]
46
+ req.env['request_tag'] = signature(sess_id, req.uuid)
47
+ end
48
+ end
49
+
50
+
51
+ # ensure tags appear on each line of a multiline log statement.
52
+ module MultilineFormatter
53
+
54
+ def call(severity, timestamp, progname, msg)
55
+ if msg && msg.index("\n")
56
+ msg.lines.map{|l| super(severity, timestamp, progname, l.chomp)}.join
57
+ else
58
+ super
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+
65
+ # Hook Rails init process
66
+ class Railtie < Rails::Railtie
67
+ initializer 'outland-tag_runes' do |app|
68
+
69
+ Rails.logger.formatter.extend MultilineFormatter
70
+
71
+ # Keep requests separated when deployed for sanity's sake
72
+ unless Rails.env.development?
73
+ ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_|
74
+ Rails.logger.info "\n\n"
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'outland/tag_runes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "outland-tag_runes"
8
+ spec.version = Outland::TagRunes::VERSION
9
+ spec.authors = ["Bill Lipa"]
10
+ spec.email = ["dojo@masterleep.com"]
11
+
12
+ spec.summary = %q{Encode Rails session and request id into the log using only 7 columns, via Unicode.}
13
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/outland/tag_runes"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "rails", ">= 5.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: outland-tag_runes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bill Lipa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - dojo@masterleep.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/outland/tag_runes.rb
71
+ - lib/outland/tag_runes/version.rb
72
+ - outland-tag_runes.gemspec
73
+ homepage: https://github.com/outland/tag_runes
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.10
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Encode Rails session and request id into the log using only 7 columns, via
97
+ Unicode.
98
+ test_files: []