scrolls 0.0.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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/lib/scrolls.rb +93 -0
- data/lib/scrolls/version.rb +3 -0
- data/scrolls.gemspec +16 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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
data/lib/scrolls.rb
ADDED
@@ -0,0 +1,93 @@
|
|
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, &blk)
|
14
|
+
end
|
15
|
+
|
16
|
+
module Log
|
17
|
+
extend self
|
18
|
+
|
19
|
+
def start
|
20
|
+
$stdout.sync = $stderr.sync = true
|
21
|
+
log(:log => true, :start => true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def mtx
|
25
|
+
@mtx ||= Mutex.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def write(data)
|
29
|
+
msg = unparse(data)
|
30
|
+
mtx.synchronize do
|
31
|
+
$stdout.puts(msg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def unparse(data)
|
36
|
+
data.map do |(k, v)|
|
37
|
+
if (v == true)
|
38
|
+
k.to_s
|
39
|
+
elsif (v == false)
|
40
|
+
"#{k}=false"
|
41
|
+
elsif v.is_a?(String) # escape and quote v with ' or \ or multiple words
|
42
|
+
v = v.gsub(/\\|'/) { |c| "\\#{c}" }
|
43
|
+
"#{k}='#{v}'"
|
44
|
+
elsif v.is_a?(Float)
|
45
|
+
"#{k}=#{format("%.3f", v)}"
|
46
|
+
else
|
47
|
+
"#{k}=#{v}"
|
48
|
+
end
|
49
|
+
end.compact.join(" ")
|
50
|
+
end
|
51
|
+
|
52
|
+
def log(data, &blk)
|
53
|
+
unless blk
|
54
|
+
write(data)
|
55
|
+
else
|
56
|
+
start = Time.now
|
57
|
+
res = nil
|
58
|
+
log(data.merge(:at => :start))
|
59
|
+
begin
|
60
|
+
res = yield
|
61
|
+
rescue StandardError, Timeout::Error => e
|
62
|
+
log(data.merge(
|
63
|
+
:at => :exception,
|
64
|
+
:reraise => true,
|
65
|
+
:class => e.class,
|
66
|
+
:message => e.message,
|
67
|
+
:exception_id => e.object_id.abs,
|
68
|
+
:elapsed => Time.now - start
|
69
|
+
))
|
70
|
+
raise(e)
|
71
|
+
end
|
72
|
+
log(data.merge(:at => :finish, :elapsed => Time.now - start))
|
73
|
+
res
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def log_exception(data, e)
|
78
|
+
log(data.merge(
|
79
|
+
:exception => true,
|
80
|
+
:class => e.class,
|
81
|
+
:message => e.message,
|
82
|
+
:exception_id => e.object_id.abs
|
83
|
+
))
|
84
|
+
e.backtrace.reverse.each do |line|
|
85
|
+
log(data.merge(
|
86
|
+
:exception => true,
|
87
|
+
:exception_id => e.object_id.abs,
|
88
|
+
:site => line.gsub(/[`'"]/, "")
|
89
|
+
))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
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 = "Heroku logging, easier, more consistent."
|
8
|
+
gem.summary = "When do we log? All the time."
|
9
|
+
gem.homepage = "https://github.com/heroku/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 = "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: scrolls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Heroku
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Heroku 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/heroku/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.11
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: When do we log? All the time.
|
53
|
+
test_files: []
|