mmcgrana-scrolls 0.0.6

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 scrolls.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © Heroku 2012
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Scrolls
2
+
3
+ Logging gem, compiled from many different internal projects in order to make
4
+ it easier to add logging to projects. Basically I grew tired of moving this
5
+ file around.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'scrolls'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scrolls
20
+
21
+ ## Usage
22
+
23
+ It's pretty easy to use:
24
+
25
+ require 'scrolls'
26
+
27
+ Put this somewhere early on in your application:
28
+
29
+ Scrolls::Log.start
30
+
31
+ Use it:
32
+
33
+ Scrolls.log(:testing => true, :at => "readme")
34
+
35
+ ## Thanks
36
+
37
+ I only compiled this library, many others made it work. Here are some of the
38
+ authors of projects that I've used to get an idea of a consistent log gem:
39
+
40
+ * Mark McGranaghan
41
+ * Noah Zoschke
42
+ * Mark Fine
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Scrolls
2
+ VERSION = "0.0.6"
3
+ end
data/lib/scrolls.rb ADDED
@@ -0,0 +1,110 @@
1
+ require "thread"
2
+
3
+ require "scrolls/version"
4
+
5
+ module Scrolls
6
+ extend self
7
+
8
+ def log(data, &blk)
9
+ Log.log(data, &blk)
10
+ end
11
+
12
+ def log_exception(data, e)
13
+ Log.log_exception(data, e)
14
+ end
15
+
16
+ module Log
17
+ extend self
18
+
19
+ attr_accessor :stream
20
+
21
+ def start(out = nil)
22
+ # This allows log_exceptions below to pick up the defined output,
23
+ # otherwise stream out to STDERR
24
+ @defined = out.nil? ? false : true
25
+ sync_stream(out)
26
+ log(:log => true, :start => true)
27
+ end
28
+
29
+ def sync_stream(out = nil)
30
+ out = STDOUT if out.nil?
31
+ @stream = out
32
+ @stream.sync = true
33
+ end
34
+
35
+ def mtx
36
+ @mtx ||= Mutex.new
37
+ end
38
+
39
+ def write(data)
40
+ msg = unparse(data)
41
+ mtx.synchronize do
42
+ @stream.puts(msg)
43
+ end
44
+ end
45
+
46
+ def unparse(data)
47
+ data.map do |(k, v)|
48
+ if (v == true)
49
+ k.to_s
50
+ elsif v.is_a?(Float)
51
+ "#{k}=#{format("%.3f", v)}"
52
+ elsif v.nil?
53
+ nil
54
+ else
55
+ v_str = v.to_s
56
+ if (v_str =~ /^[a-zA-z0-9\-\_\.]+$/)
57
+ "#{k}=#{v_str}"
58
+ else
59
+ "#{k}=\"#{v_str.sub(/".*/, "...")}\""
60
+ end
61
+ end
62
+ end.compact.join(" ")
63
+ end
64
+
65
+ def log(data, &blk)
66
+ unless blk
67
+ write(data)
68
+ else
69
+ start = Time.now
70
+ res = nil
71
+ log(data.merge(:at => :start))
72
+ begin
73
+ res = yield
74
+ rescue StandardError, Timeout::Error => e
75
+ log(data.merge(
76
+ :at => :exception,
77
+ :reraise => true,
78
+ :class => e.class,
79
+ :message => e.message,
80
+ :exception_id => e.object_id.abs,
81
+ :elapsed => Time.now - start
82
+ ))
83
+ raise(e)
84
+ end
85
+ log(data.merge(:at => :finish, :elapsed => Time.now - start))
86
+ res
87
+ end
88
+ end
89
+
90
+ def log_exception(data, e)
91
+ sync_stream(STDERR) unless @defined
92
+ log(data.merge(
93
+ :exception => true,
94
+ :class => e.class,
95
+ :message => e.message,
96
+ :exception_id => e.object_id.abs
97
+ ))
98
+ if e.backtrace
99
+ bt = e.backtrace.reverse
100
+ bt[0, bt.size-6].each do |line|
101
+ log(data.merge(
102
+ :exception => true,
103
+ :exception_id => e.object_id.abs,
104
+ :site => line.gsub(/[`'"]/, "")
105
+ ))
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
data/scrolls.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/scrolls/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Heroku"]
6
+ gem.email = ["curt@heroku.com"]
7
+ gem.description = "Logging, easier, more consistent."
8
+ gem.summary = "When do we log? All the time."
9
+ gem.homepage = "https://github.com/asenchi/scrolls"
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "mmcgrana-scrolls"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Scrolls::VERSION
16
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmcgrana-scrolls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Heroku
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Logging, easier, more consistent.
15
+ email:
16
+ - curt@heroku.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/scrolls.rb
27
+ - lib/scrolls/version.rb
28
+ - scrolls.gemspec
29
+ homepage: https://github.com/asenchi/scrolls
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.21
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: When do we log? All the time.
53
+ test_files: []