l2metable 0.0.2
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.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/l2metable.gemspec +23 -0
- data/lib/l2metable.rb +109 -0
- data/lib/l2metable/version.rb +3 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ericfode
|
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,29 @@
|
|
1
|
+
# Loggable
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'loggable'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install loggable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/l2metable.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'l2metable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "l2metable"
|
8
|
+
spec.version = L2Metable::VERSION
|
9
|
+
spec.authors = ["ericfode","ryanbrainard"]
|
10
|
+
spec.email = ["ericfode@gmail.com"]
|
11
|
+
spec.description = %q{A mixin to add some nice logging functions that log in the l2met style}
|
12
|
+
spec.summary = %q{l2met logging mixin}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/l2metable.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require "l2metable/version"
|
2
|
+
|
3
|
+
module L2Metable
|
4
|
+
|
5
|
+
# Descendants should override and implement a specific component prefix for all log lines
|
6
|
+
# e.g. "widget#{subcomponent}"
|
7
|
+
#
|
8
|
+
def log_component(subcomponent)
|
9
|
+
subcomponent
|
10
|
+
end
|
11
|
+
|
12
|
+
# Descendants should override and implement a specific base hash for all log lines, if applicable
|
13
|
+
# e.g. {:app_id => @app_id, :xid => context.xid}
|
14
|
+
#
|
15
|
+
def log_base_hash()
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Descendants should override and implement a specific log handler
|
20
|
+
# e.g. @logger.write(full_msg)
|
21
|
+
#
|
22
|
+
def log_write(msg)
|
23
|
+
puts msg
|
24
|
+
end
|
25
|
+
|
26
|
+
def monitor(subcomponent, extras = {}, &blk)
|
27
|
+
unless block_given?
|
28
|
+
# should never enter, but logging with something obvious instead of blowing up at runtime
|
29
|
+
measure(dotted(subcomponent, "MONITOR_WITHOUT_BLOCK"), 1, extras)
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
start = Time.now
|
34
|
+
measure(dotted(subcomponent, "start"), 1, extras)
|
35
|
+
|
36
|
+
res = nil
|
37
|
+
ex = nil
|
38
|
+
begin
|
39
|
+
res = yield
|
40
|
+
rescue => e
|
41
|
+
log_exception(subcomponent, e, extras)
|
42
|
+
ex = e
|
43
|
+
end
|
44
|
+
|
45
|
+
measure(dotted(subcomponent, "time"), Time.now - start, extras)
|
46
|
+
|
47
|
+
if ex
|
48
|
+
raise(ex)
|
49
|
+
else
|
50
|
+
res
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def measure(subcomponent, value, extras = {})
|
55
|
+
comp = log_component(subcomponent)
|
56
|
+
log_hash({("measure#"+ comp) => value}.merge(extras))
|
57
|
+
end
|
58
|
+
|
59
|
+
def sample(subcomponent, value, extras = {})
|
60
|
+
comp = log_component(subcomponent)
|
61
|
+
log_hash({("sample#"+ comp) => value}.merge(extras))
|
62
|
+
end
|
63
|
+
|
64
|
+
def count(subcomponent, value=1, extras ={})
|
65
|
+
comp = log_component(subcomponent)
|
66
|
+
log_hash({("count#"+ comp) => value}.merge(extras))
|
67
|
+
end
|
68
|
+
|
69
|
+
def log_exception(subcomponent, e, extras = {})
|
70
|
+
exception_suffix = "exception"
|
71
|
+
extras = {:at => dotted(log_component(subcomponent), exception_suffix)}.merge(extras)
|
72
|
+
|
73
|
+
if e.nil? || !e.is_a?(Exception)
|
74
|
+
measure(exception_suffix, 1, extras)
|
75
|
+
return
|
76
|
+
end
|
77
|
+
|
78
|
+
exception_id = e.object_id.abs
|
79
|
+
trace = e.backtrace.reduce do |memo, line|
|
80
|
+
memo + line.gsub(/[`'"]/, "") + "\n"
|
81
|
+
end
|
82
|
+
measure(exception_suffix, 1, {
|
83
|
+
:exception_id => exception_id,
|
84
|
+
:class => e.class,
|
85
|
+
:message => e.message,
|
86
|
+
:trace => trace
|
87
|
+
}.merge(extras))
|
88
|
+
end
|
89
|
+
|
90
|
+
def join_hash(hash = {})
|
91
|
+
hash.map do |k, v|
|
92
|
+
if v.is_a? Float
|
93
|
+
# workaround for old Ruby version on Bamboo not having parameterized round()
|
94
|
+
v = (v * 1000).round() / 1000.0
|
95
|
+
elsif v.to_s =~ /\s/
|
96
|
+
v = "\"#{v}\""
|
97
|
+
end
|
98
|
+
"#{k}=#{v}"
|
99
|
+
end.join(" ")
|
100
|
+
end
|
101
|
+
|
102
|
+
def log_hash(hash = {})
|
103
|
+
log_write(join_hash(log_base_hash.merge(hash)))
|
104
|
+
end
|
105
|
+
|
106
|
+
def dotted(*pieces)
|
107
|
+
(pieces.reject { |e| e.nil? || (e.respond_to?('empty?') && e.empty?) }).join('.')
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: l2metable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ericfode
|
9
|
+
- ryanbrainard
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
none: false
|
29
|
+
prerelease: false
|
30
|
+
type: :development
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
none: false
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
none: false
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
description: A mixin to add some nice logging functions that log in the l2met style
|
48
|
+
email:
|
49
|
+
- ericfode@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- l2metable.gemspec
|
60
|
+
- lib/l2metable.rb
|
61
|
+
- lib/l2metable/version.rb
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
none: false
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
none: false
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: l2met logging mixin
|
87
|
+
test_files: []
|