log_runes 1.1.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in log_runes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 William Lipa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Log Runes
2
+
3
+ The Log Runes gem adds unicode glyphs to the Rails logger output that encode the session and request id
4
+ in a way that occupies a minimum of visual space but provides very useful debugging capabilities.
5
+
6
+ For example, it is easy to grep for a single session's log output, or the log output for a complete
7
+ request, even if many requests are interleaved into the same log file.
8
+
9
+ Beyond the debugging capabilities, Runic Logs tries to keep the log file output pleasant to work
10
+ with by only occupying 10 columns of text. It uses unicode to encode a full byte of data into each
11
+ column position in a visually clear way.
12
+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'log_runes'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install log_runes
27
+
28
+
29
+ ## Usage
30
+
31
+ Add the following setting to your config/application.rb file:
32
+
33
+ config.log_tags = [ LogRunes.tag ]
34
+
35
+ Your log output will look something like the following.
36
+
37
+ [★¿xÄ ϱm] Completed 200 OK in 78ms (Views: 0.7ms | ActiveRecord: 72.6ms)
38
+
39
+ The format is:
40
+
41
+ [<encoded session id> <encoded request id>]
42
+
43
+ So to look at a user's complete session log output, do the following:
44
+
45
+ grep "<encoded session id>" production.log
46
+
47
+ Or for a particular request:
48
+
49
+ grep "<encoded request id>" production.log
50
+
51
+ The tag is added to the Rack environment, so tools like Airbrake will contain it in
52
+ their exception environment information. You can therefore look at a recorded exception
53
+ and immediately produce the entire log output for that request.
54
+
55
+ The glyphs were chosen for legibility in OSX terminal fonts. The standard terminal does
56
+ slow down quite a bit when there are many unicode characters; to get around this, use
57
+ the almost identical but significantly faster iTerm 2.
58
+
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ module LogRunes
2
+ class Cronolog
3
+
4
+ def self.setup(config, log_base)
5
+ unless File.exists? '/usr/bin/cronolog'
6
+ puts "cronolog missing - reverting to standard logger"
7
+ return
8
+ end
9
+ crono_cmd = "/usr/bin/cronolog -S #{log_base}/#{Rails.env}.log #{log_base}/rot/#{Rails.env}-%Y-%m-%d.log"
10
+ config.logger = ActiveSupport::TaggedLogging.new(Logger.new(IO.popen(crono_cmd, "w")))
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ module LogRunes
4
+ class SessionRequestTagger
5
+
6
+ # These glyphs should be chosen to maximize visual distinctiveness
7
+ # while being available in OSX 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.proc
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
+ req.env['request_tag'] = signature(req.cookies['_session_id'], req.uuid)
46
+ end
47
+ end
48
+
49
+ def self.wrap(wrapee)
50
+
51
+ class << wrapee
52
+
53
+ alias_method :add_original, :add
54
+
55
+ # Tag each line if multiple are passed in.
56
+ def add(severity, message = nil, progname = nil, &block)
57
+ message = (block_given? ? block.call : progname) if message.nil?
58
+ if message && message.include?("\n")
59
+ message.lines{|l| add_original(severity, l.chomp)}
60
+ else
61
+ add_original(severity, message)
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module LogRunes
2
+ VERSION = "1.1.1"
3
+ end
data/lib/log_runes.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "log_runes/cronolog"
2
+ require "log_runes/session_request_tagger"
3
+ require "log_runes/version"
4
+
5
+ module LogRunes
6
+
7
+ def self.tag
8
+ SessionRequestTagger.proc
9
+ end
10
+
11
+ # Hook Rails init process
12
+ class Railtie < Rails::Railtie
13
+ initializer 'log_runes' do |app|
14
+
15
+ SessionRequestTagger.wrap(Rails.logger)
16
+
17
+ # Keep requests separated when deployed for sanity's sake
18
+ unless Rails.env.development?
19
+ ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_|
20
+ Rails.logger.info "\n\n"
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ end
data/log_runes.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'log_runes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "log_runes"
8
+ gem.version = LogRunes::VERSION
9
+ gem.authors = ["wlipa"]
10
+ gem.email = ["dojo@masterleep.com"]
11
+ gem.description = %q{Encodes session and request ids into the Rails log output using Unicode single-width characters, thereby using only a minimum amount of column width but allowing easy grepping for an individual session or request.}
12
+ gem.summary = %q{Encodes session and request ids into the Rails log output for easy grepping}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_runes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - wlipa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Encodes session and request ids into the Rails log output using Unicode
15
+ single-width characters, thereby using only a minimum amount of column width but
16
+ allowing easy grepping for an individual session or request.
17
+ email:
18
+ - dojo@masterleep.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/log_runes.rb
29
+ - lib/log_runes/cronolog.rb
30
+ - lib/log_runes/session_request_tagger.rb
31
+ - lib/log_runes/version.rb
32
+ - log_runes.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.25
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Encodes session and request ids into the Rails log output for easy grepping
57
+ test_files: []