log_syringe 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.simplecov +9 -0
- data/.travis.yml +5 -0
- data/.yardopts +5 -0
- data/Gemfile +5 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +73 -0
- data/Rakefile +7 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/log_syringe.rb +25 -0
- data/lib/log_syringe/dsl.rb +72 -0
- data/lib/log_syringe/version.rb +5 -0
- data/log_syringe.gemspec +35 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 778a39f06f29bd4e07ad07c7617bdd7de4c61a28
|
4
|
+
data.tar.gz: 18cc51c5db478d24981ff844d744a026bb2e9b0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f164a1cd231ee857271969aff419d80f7addb10e91e886a695f883c8090f822cda1a8cd5e7519e5a3f6d39c6e1146127bc1b6a44421ac82a42c8047b28d81bbb
|
7
|
+
data.tar.gz: 1c04a6a12a1a6ee44b58fb3a97740dacd822a4b8348a505af783f1a1ef775bece94d6a75c1994cfcff12c3a32b52150cdae80465ee97eba61638794a6c835421
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require 'guard/rspec/dsl'
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# RSpec files
|
6
|
+
rspec = dsl.rspec
|
7
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
9
|
+
watch(rspec.spec_files)
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
ruby = dsl.ruby
|
13
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
14
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 MESO Digital Services GmbH
|
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,73 @@
|
|
1
|
+
# LogSyringe
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/meso-unimpressed/log_syringe.svg?branch=master)](https://travis-ci.org/meso-unimpressed/log_syringe)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/meso-unimpressed/log_syringe/badges/gpa.svg)](https://codeclimate.com/github/meso-unimpressed/log_syringe)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/meso-unimpressed/log_syringe/badges/coverage.svg)](https://codeclimate.com/github/meso-unimpressed/log_syringe/coverage)
|
6
|
+
|
7
|
+
Add logging to your application without cluttering your code with logger calls.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'log_syringe'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install log_syringe
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Write your code:
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
class MyClass
|
31
|
+
def some_method(an_argument)
|
32
|
+
do_something
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Set up a logger for LogSyringe:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
LogSyringe.logger = Logger.new(STDOUT)
|
41
|
+
```
|
42
|
+
|
43
|
+
Inject logging with LogSyringe:
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
LogSyringe.define(MyClass) do
|
47
|
+
log_method(:some_method) do |logger, instance, stats|
|
48
|
+
logger.info(
|
49
|
+
"some_method was called in #{instance} with params #{stats[:params]}"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
For full documentation see http://www.rubydoc.info/github/meso-unimpressed/log_syringe/master
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
60
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
61
|
+
prompt that will allow you to experiment.
|
62
|
+
|
63
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
64
|
+
release a new version, update the version number in `version.rb`, and then run
|
65
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
66
|
+
git commits and tags, and push the `.gem` file to
|
67
|
+
[rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at
|
72
|
+
https://github.com/meso-unimpressed/log_syringe.
|
73
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'log_syringe'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/log_syringe.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'log_syringe/version'
|
3
|
+
require 'log_syringe/dsl'
|
4
|
+
|
5
|
+
# Top level namespace
|
6
|
+
module LogSyringe
|
7
|
+
class << self
|
8
|
+
# The logger to be passed to log_method blocks
|
9
|
+
attr_accessor :logger
|
10
|
+
|
11
|
+
# Define logging for a class/module
|
12
|
+
# @param klass [Module] The class or module to define logging for
|
13
|
+
# @example
|
14
|
+
# LogSyringe.define(MyClass) do
|
15
|
+
# log_method(:some_method) do |logger, instance, stats|
|
16
|
+
# logger.info(
|
17
|
+
# "some method called on #{instance} with #{stats[:args]}"
|
18
|
+
# )
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
def define(klass, &block)
|
22
|
+
DSL.new(klass, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module LogSyringe
|
3
|
+
# DSL that is exposed for defining logging
|
4
|
+
class DSL
|
5
|
+
def initialize(klass, &block)
|
6
|
+
@klass = klass
|
7
|
+
@logging_layer = Module.new
|
8
|
+
instance_eval(&block)
|
9
|
+
klass.prepend(@logging_layer)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Wrap a given method with logging
|
13
|
+
# @param name [Symbol] The method to wrap
|
14
|
+
# @yieldparam logger [Logger] The global logger instance
|
15
|
+
# @yieldparam instance The instance the method was called on
|
16
|
+
# @yieldparam stats [Hash] Information about the method call.
|
17
|
+
# It contains the following information: +:args [Array]+ the arguments the
|
18
|
+
# method was called with, +:error [Error]+ the error that was
|
19
|
+
# raised (if any), +:result+ the return value of the method
|
20
|
+
# (if no exception was raised), +:runtime+ the runtime for the method
|
21
|
+
# (if no exception was raised).
|
22
|
+
# @example
|
23
|
+
# log_method(:some_method) do |logger, instance, stats|
|
24
|
+
# logger.info(
|
25
|
+
# "some_method called on #{instance} with args #{stats[:args]}. " \
|
26
|
+
# "runtime: #{stats[:runtime]}"
|
27
|
+
# )
|
28
|
+
# end
|
29
|
+
def log_method(name, &block)
|
30
|
+
check_method_exists!(name)
|
31
|
+
define_logging_method(
|
32
|
+
name, method(:measure_runtime), method(:logging), &block
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def measure_runtime
|
39
|
+
started = Time.now
|
40
|
+
yield_result = yield
|
41
|
+
[yield_result, Time.now - started]
|
42
|
+
end
|
43
|
+
|
44
|
+
def logging(instance, args, error, result, runtime)
|
45
|
+
yield(
|
46
|
+
LogSyringe.logger, instance,
|
47
|
+
args: args,
|
48
|
+
error: error,
|
49
|
+
result: result,
|
50
|
+
runtime: runtime
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def define_logging_method(name, measure_runtime, logging, &dsl_block)
|
55
|
+
@logging_layer.send(:define_method, name) do |*args, &block|
|
56
|
+
begin
|
57
|
+
result, runtime = measure_runtime.call { super(*args, &block) }
|
58
|
+
logging.call(self, args, nil, result, runtime, &dsl_block)
|
59
|
+
result
|
60
|
+
rescue StandardError => error
|
61
|
+
logging.call(self, args, error, nil, nil, &dsl_block)
|
62
|
+
raise error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_method_exists!(name)
|
68
|
+
return if @klass.instance_methods.include?(name)
|
69
|
+
raise ArgumentError, "#{@klass} does not define method #{name}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/log_syringe.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'log_syringe/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'log_syringe'
|
9
|
+
spec.version = LogSyringe::VERSION
|
10
|
+
spec.authors = ['Joakim Reinert']
|
11
|
+
spec.email = ['reinert@meso.net']
|
12
|
+
|
13
|
+
spec.summary = 'Unintrusive logging for ruby applications'
|
14
|
+
spec.description =
|
15
|
+
'Adds logging to your application without cluttering your code with ' \
|
16
|
+
'logger calls'
|
17
|
+
spec.homepage = 'https://github.com/meso-unimpressed/log_syringe'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{spec/})
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.4'
|
29
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.8'
|
30
|
+
spec.add_development_dependency 'guard', '~> 2.1'
|
31
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
32
|
+
spec.add_development_dependency 'timecop', '~> 0.8'
|
33
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.1'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_syringe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joakim Reinert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.1'
|
153
|
+
description: Adds logging to your application without cluttering your code with logger
|
154
|
+
calls
|
155
|
+
email:
|
156
|
+
- reinert@meso.net
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".ruby-version"
|
164
|
+
- ".simplecov"
|
165
|
+
- ".travis.yml"
|
166
|
+
- ".yardopts"
|
167
|
+
- Gemfile
|
168
|
+
- Guardfile
|
169
|
+
- LICENSE
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- bin/console
|
173
|
+
- bin/setup
|
174
|
+
- lib/log_syringe.rb
|
175
|
+
- lib/log_syringe/dsl.rb
|
176
|
+
- lib/log_syringe/version.rb
|
177
|
+
- log_syringe.gemspec
|
178
|
+
homepage: https://github.com/meso-unimpressed/log_syringe
|
179
|
+
licenses: []
|
180
|
+
metadata: {}
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.5.1
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Unintrusive logging for ruby applications
|
201
|
+
test_files: []
|