easy_logging 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ec34fd51402cfc73189bc9f9abd0b61b889f5e4
4
- data.tar.gz: d535f3bfe5bc2b9576a22451d5584787be92e175
3
+ metadata.gz: b037526760133fc13b0acb182b872a760ef3eb47
4
+ data.tar.gz: 11ceca27d8bef25e0801bf47c984e6a868cbd514
5
5
  SHA512:
6
- metadata.gz: 625ed39af3bdc60408da1b2e0489cc1395836dfb459810bfc81655429300ffb697c8a0d266f7a86d8e66e2a07ef3dc4898a4a8eaa039a800ac729a5e9df9bb2b
7
- data.tar.gz: 804e114bcf99ad8259549f7efadcfa4da08a2da1643a6ddb7cfaec259cedba0f0ddd725871e27f60c1314cc7f65e49953e69b10ffe50f517ef2c2df1f98380ba
6
+ metadata.gz: 5e1759eef678a446a867585c929eabc85e99a742263ad29a190d1fb6acbcb0eaf74f198d68424530a7f11aa2912e508adb13f082378e6dd66e7f925445dce2fb
7
+ data.tar.gz: e283230e578c06c8bf98a1ade97c67c25c23968077543ce5904060b667d49b23c68d49158661bac7e521f094eaa83f7ae309fe98286876f8298a641ecda51f4e
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ .idea
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(%r{^(.+)\.gemspec$})
4
+ end
5
+
6
+ guard 'rspec', cmd: "bundle exec spring rspec #{ENV['FOCUS']}", all_after_pass: ENV['FOCUS'].nil? do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/builders/#{m[1]}_builder_spec.rb" }
14
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
15
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
16
+ watch(%r{^spec/factories/(.+)\.rb$}) { 'spec' }
17
+ watch('config/routes.rb') { 'spec/routing' }
18
+ watch('app/controllers/application_controller.rb') { 'spec/controllers' }
19
+
20
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
21
+ end
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017
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 all
13
- 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 THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,102 +1,142 @@
1
- # EasyLogging
2
-
3
- #### Ruby utility that lets you include logging anywhere easily, without redundancy.
4
-
5
- | Branch | Status |
6
- | ------ | ------ |
7
- | Release | [![Build Status](https://travis-ci.org/thisismydesign/easy_logging.svg?branch=release)](https://travis-ci.org/thisismydesign/easy_logging) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/easy_logging/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/easy_logging?branch=release) [![Gem Version](https://badge.fury.io/rb/easy_logging.svg)](https://badge.fury.io/rb/easy_logging) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/easy_logging?type=total)](https://rubygems.org/gems/easy_logging) |
8
- | Development | [![Build Status](https://travis-ci.org/thisismydesign/easy_logging.svg?branch=master)](https://travis-ci.org/thisismydesign/easy_logging) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/easy_logging/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/easy_logging?branch=master) |
9
-
10
- ## Features
11
-
12
- - Adds logging functionality anywhere with one, short, self-descriptive command
13
- - Logger works in both class and instance methods
14
- - Logger is specific to class and contains class name
15
- - Logger is configurable to use standard streams or file
16
-
17
- ## Installation
18
-
19
- Add this line to your application's Gemfile:
20
-
21
- ```ruby
22
- gem 'easy_logging'
23
- ```
24
-
25
- And then execute:
26
-
27
- $ bundle
28
-
29
- Or install it yourself as:
30
-
31
- $ gem install easy_logging
32
-
33
- ## Usage
34
-
35
- Add `include EasyLogging` to any context (e.g. a class) you want to extend with logging functionality.
36
-
37
- ```ruby
38
- require 'easy_logging'
39
- EasyLogging.log_destination = 'app.log'
40
-
41
- class YourClass
42
- include EasyLogging
43
-
44
- def do_something
45
- # ...
46
- logger.info 'something happened'
47
- end
48
- end
49
-
50
- class YourOtherClass
51
- include EasyLogging
52
-
53
- def self.do_something
54
- # ...
55
- logger.info 'something happened'
56
- end
57
- end
58
-
59
- YourClass.new.do_something
60
- YourOtherClass.do_something
61
- ```
62
-
63
- Output:
64
- ```
65
- I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourClass: something happened
66
- I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourOtherClass: something happened
67
- ```
68
-
69
- ## Configuration
70
-
71
- \[Since [v0.2.0](https://github.com/thisismydesign/easy_logging/releases/tag/v0.2.0)]
72
-
73
- You can configure log destination as:
74
-
75
- `EasyLogging.log_destination = 'app.log'`
76
-
77
- Otherwise it will default to `STDOUT`.
78
-
79
- Important notes:
80
- - Log destination setting is global for all loggers
81
- - It is recommended to require EasyLogging and set the logger up properly in the initial setup of your application before any logging activity
82
- - Changing log destination on the fly will affect all future and not yet used loggers, however already used ones will log to the original destination
83
-
84
- ## Feedback
85
-
86
- Any feedback is much appreciated.
87
-
88
- I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
89
-
90
- Please let me know if you make use of this project so that I can prioritize further efforts.
91
-
92
- ## Development
93
-
94
- This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
95
-
96
- ## Contributing
97
-
98
- Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/easy_logging.
99
-
100
- ## License
101
-
102
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
1
+ # EasyLogging
2
+
3
+ #### Ruby utility that lets you include logging anywhere easily, without redundancy.
4
+
5
+ | Branch | Status |
6
+ | ------ | ------ |
7
+ | Release | [![Build Status](https://travis-ci.org/thisismydesign/easy_logging.svg?branch=release)](https://travis-ci.org/thisismydesign/easy_logging) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/easy_logging/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/easy_logging?branch=release) [![Gem Version](https://badge.fury.io/rb/easy_logging.svg)](https://badge.fury.io/rb/easy_logging) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/easy_logging?type=total)](https://rubygems.org/gems/easy_logging) |
8
+ | Development | [![Build Status](https://travis-ci.org/thisismydesign/easy_logging.svg?branch=master)](https://travis-ci.org/thisismydesign/easy_logging) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/easy_logging/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/easy_logging?branch=master) |
9
+
10
+ ## Features
11
+
12
+ - Adds logging functionality anywhere with one, short, descriptive command
13
+ - Logger works in both class and instance methods
14
+ - Logger is specific to class and contains class name
15
+ - Logger is configurable to use standard streams or file
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'easy_logging'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install easy_logging
32
+
33
+ ## Usage
34
+
35
+ Add `include EasyLogging` to any context (e.g. a class) you want to extend with logging functionality.
36
+
37
+ ```ruby
38
+ require 'easy_logging'
39
+ EasyLogging.log_destination = 'app.log'
40
+ EasyLogging.level = Logger::DEBUG
41
+
42
+ class YourClass
43
+ include EasyLogging
44
+
45
+ def do_something
46
+ # ...
47
+ logger.info 'something happened'
48
+ end
49
+ end
50
+
51
+ class YourOtherClass
52
+ include EasyLogging
53
+
54
+ def self.do_something
55
+ # ...
56
+ logger.info 'something happened'
57
+ end
58
+ end
59
+
60
+ YourClass.new.do_something
61
+ YourOtherClass.do_something
62
+ ```
63
+
64
+ Output:
65
+ ```
66
+ I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourClass: something happened
67
+ I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourOtherClass: something happened
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ **Log settings are global for all loggers. Always configure EasyLogging before loading your application.**
73
+
74
+ #### Destination
75
+
76
+ ```ruby
77
+ EasyLogging.log_destination = 'app.log'
78
+ ```
79
+
80
+ Default: `STDOUT`
81
+
82
+ Since: [v0.2.0](https://github.com/thisismydesign/easy_logging/releases/tag/v0.2.0)
83
+
84
+ #### Level
85
+
86
+ ```ruby
87
+ EasyLogging.level = Logger::DEBUG
88
+ ```
89
+
90
+ Default: `Logger::INFO`
91
+
92
+ Since: [v0.3.0](https://github.com/thisismydesign/easy_logging/releases/tag/v0.3.0)
93
+
94
+ #### Formatter
95
+
96
+ ```ruby
97
+ EasyLogging.formatter = proc do |severity, datetime, progname, msg|
98
+ severity + datetime + progname + msg
99
+ end
100
+ ```
101
+
102
+ Default: Logger default
103
+
104
+ Since: [v0.3.0](https://github.com/thisismydesign/easy_logging/releases/tag/v0.3.0)
105
+
106
+ #### Changing configuration on the fly
107
+
108
+ ... is tricky but looking at the specs it's fairly easy to understand:
109
+
110
+ ```ruby
111
+ describe 'on the fly modification of logger configuration' do
112
+ context 'class level logger' do
113
+ it 'uses old config if EasyLogging was included before config change'
114
+ it 'uses new config if EasyLogging was included after config change'
115
+ end
116
+
117
+ context 'instance level logger' do
118
+ it 'uses old config if instance was created before config change'
119
+ it 'uses new config if instance was created after config change'
120
+ end
121
+ end
122
+ ```
123
+
124
+ ## Feedback
125
+
126
+ Any feedback is much appreciated.
127
+
128
+ I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
129
+
130
+ Please let me know if you make use of this project so that I can prioritize further efforts.
131
+
132
+ ## Development
133
+
134
+ This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
135
+
136
+ ## Contributing
137
+
138
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/easy_logging.
139
+
140
+ ## License
141
+
142
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/easy_logging.gemspec CHANGED
@@ -1,26 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'easy_logging/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "easy_logging"
8
- spec.version = EasyLogging::VERSION
9
- spec.authors = ["thisismydesign"]
10
- spec.email = ["thisismydesign@users.noreply.github.com"]
11
-
12
- spec.summary = "Include logging anywhere easily, without redundancy."
13
- spec.homepage = "https://github.com/thisismydesign/easy_logging"
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
17
- end
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.14"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
25
- spec.add_development_dependency "coveralls"
26
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easy_logging/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy_logging"
8
+ spec.version = EasyLogging::VERSION
9
+ spec.authors = ["thisismydesign"]
10
+ spec.email = ["thisismydesign@users.noreply.github.com"]
11
+
12
+ spec.summary = "Include logging anywhere easily, without redundancy."
13
+ spec.homepage = "https://github.com/thisismydesign/easy_logging"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "guard"
27
+ spec.add_development_dependency "guard-bundler"
28
+ spec.add_development_dependency "guard-rspec"
29
+ end
@@ -1,3 +1,3 @@
1
- module EasyLogging
2
- VERSION = "0.2.0"
3
- end
1
+ module EasyLogging
2
+ VERSION = "0.3.0"
3
+ end
data/lib/easy_logging.rb CHANGED
@@ -1,43 +1,56 @@
1
- require 'logger'
2
-
3
- require_relative "easy_logging/version"
4
-
5
- module EasyLogging
6
-
7
- @log_destination = nil
8
- @loggers = {}
9
-
10
- def logger
11
- @logger ||= EasyLogging.logger_for(self.class.name)
12
- end
13
-
14
- def self.log_destination= dest
15
- @log_destination = dest
16
- end
17
-
18
- private
19
-
20
- # Executed when the module is included. See: https://stackoverflow.com/a/5160822/2771889
21
- def self.included(base)
22
- # Class level logger method for includer class (base)
23
- def base.logger
24
- @logger ||= EasyLogging.logger_for(self)
25
- end
26
- end
27
-
28
- # Global, memoized, lazy initialized instance of a logger
29
- def self.logger_for(classname)
30
- @loggers[classname] ||= configure_logger_for(classname)
31
- end
32
-
33
- def self.configure_logger_for(classname)
34
- logger = Logger.new(log_destination)
35
- logger.progname = classname
36
- logger
37
- end
38
-
39
- def self.log_destination
40
- @log_destination or STDOUT
41
- end
42
-
43
- end
1
+ require 'logger'
2
+
3
+ require_relative "easy_logging/version"
4
+
5
+ module EasyLogging
6
+
7
+ def initialize
8
+ super
9
+ # Initialize instance level logger at the time of instance creation
10
+ logger
11
+ end
12
+
13
+ class << self; attr_accessor :log_destination, :level, :formatter; end
14
+
15
+ @log_destination = STDOUT
16
+ @level = Logger::INFO
17
+ @loggers = {}
18
+
19
+ def logger
20
+ @logger ||= EasyLogging.logger_for(self.class.name)
21
+ end
22
+
23
+ def self.log_destination=(dest)
24
+ @log_destination = dest
25
+ end
26
+
27
+ def self.level=(level)
28
+ @level = level
29
+ end
30
+
31
+ private
32
+
33
+ # Executed when the module is included. See: https://stackoverflow.com/a/5160822/2771889
34
+ def self.included(base)
35
+ # Class level logger method for includer class (base)
36
+ def base.logger
37
+ @logger ||= EasyLogging.logger_for(self)
38
+ end
39
+ # Initialize class level logger at the time of including
40
+ base.logger
41
+ end
42
+
43
+ # Global, memoized, lazy initialized instance of a logger
44
+ def self.logger_for(classname)
45
+ @loggers[classname] ||= configure_logger_for(classname)
46
+ end
47
+
48
+ def self.configure_logger_for(classname)
49
+ logger = Logger.new(log_destination)
50
+ logger.level = level
51
+ logger.progname = classname
52
+ logger.formatter = formatter unless formatter.nil?
53
+ logger
54
+ end
55
+
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-10 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
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: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  description:
70
112
  email:
71
113
  - thisismydesign@users.noreply.github.com
@@ -77,6 +119,7 @@ files:
77
119
  - ".rspec"
78
120
  - ".travis.yml"
79
121
  - Gemfile
122
+ - Guardfile
80
123
  - LICENSE
81
124
  - README.md
82
125
  - Rakefile
@@ -104,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
147
  version: '0'
105
148
  requirements: []
106
149
  rubyforge_project:
107
- rubygems_version: 2.5.2
150
+ rubygems_version: 2.6.11
108
151
  signing_key:
109
152
  specification_version: 4
110
153
  summary: Include logging anywhere easily, without redundancy.