easy_logging 0.1.1 → 0.2.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: c1e31f8b6903552ad3609fcc9c3548d7a7119e15
4
- data.tar.gz: 39456af89e6b82d9d4387d1c1e2e4b1bf2462be7
3
+ metadata.gz: 5ec34fd51402cfc73189bc9f9abd0b61b889f5e4
4
+ data.tar.gz: d535f3bfe5bc2b9576a22451d5584787be92e175
5
5
  SHA512:
6
- metadata.gz: c2c5598b42550ad4213026ce488262b74bd701058b7168b39e2ec308fab8e599d764ee145eae0c9dceb55b01c7c6ce6e70279de8d1eef239bc0ce6994fca2e29
7
- data.tar.gz: 7d9246e6b9d3592f8c2bed57c642fe3b7800c0e77822cc3cf7884897dfe225dd9afb01de9652c80be1fa0eec07c0671b20ae8656534951aa3c2abc136ad896ad
6
+ metadata.gz: 625ed39af3bdc60408da1b2e0489cc1395836dfb459810bfc81655429300ffb697c8a0d266f7a86d8e66e2a07ef3dc4898a4a8eaa039a800ac729a5e9df9bb2b
7
+ data.tar.gz: 804e114bcf99ad8259549f7efadcfa4da08a2da1643a6ddb7cfaec259cedba0f0ddd725871e27f60c1314cc7f65e49953e69b10ffe50f517ef2c2df1f98380ba
data/README.md CHANGED
@@ -1,104 +1,102 @@
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
-
16
- ### Logger configuration
17
-
18
- - Logs to STDOUT
19
- - Contains classname
20
-
21
- Excerpt:
22
-
23
- ```ruby
24
- def self.configure_logger_for(classname)
25
- logger = Logger.new(STDOUT)
26
- logger.progname = classname
27
- logger
28
- end
29
- ```
30
-
31
- ### Possible improvements
32
-
33
- - Make logger configurable (especially the output)
34
-
35
- ## Installation
36
-
37
- Add this line to your application's Gemfile:
38
-
39
- ```ruby
40
- gem 'easy_logging'
41
- ```
42
-
43
- And then execute:
44
-
45
- $ bundle
46
-
47
- Or install it yourself as:
48
-
49
- $ gem install easy_logging
50
-
51
- ## Usage
52
-
53
- Add `include EasyLogging` to any context (e.g. a class) you want to extend with logging functionality.
54
-
55
- ```ruby
56
- require 'easy_logging'
57
-
58
- class YourClass
59
- include EasyLogging
60
-
61
- def do_something
62
- # ...
63
- logger.info 'something happened'
64
- end
65
- end
66
-
67
- class YourOtherClass
68
- include EasyLogging
69
-
70
- def self.do_something
71
- # ...
72
- logger.info 'something happened'
73
- end
74
- end
75
-
76
- YourClass.new.do_something
77
- YourOtherClass.do_something
78
- ```
79
-
80
- Output:
81
- ```
82
- I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourClass: something happened
83
- I, [2017-06-03T21:59:25.160686 #5900] INFO -- YourOtherClass: something happened
84
- ```
85
-
86
- ## Feedback
87
-
88
- Any feedback is much appreciated.
89
-
90
- 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.
91
-
92
- Please let me know if you make use of this project so that I can prioritize further efforts.
93
-
94
- ## Development
95
-
96
- This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
97
-
98
- ## Contributing
99
-
100
- Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/easy_logging.
101
-
102
- ## License
103
-
104
- 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, 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).
data/easy_logging.gemspec CHANGED
@@ -1,26 +1,26 @@
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
+ end
@@ -1,3 +1,3 @@
1
- module EasyLogging
2
- VERSION = "0.1.1"
3
- end
1
+ module EasyLogging
2
+ VERSION = "0.2.0"
3
+ end
data/lib/easy_logging.rb CHANGED
@@ -1,32 +1,43 @@
1
- require 'logger'
2
-
3
- require_relative "easy_logging/version"
4
-
5
- module EasyLogging
6
-
7
- @loggers = {}
8
-
9
- def logger
10
- @logger ||= EasyLogging.logger_for(self.class.name)
11
- end
12
-
13
- # Executed when the module is included. See: https://stackoverflow.com/a/5160822/2771889
14
- def self.included(base)
15
- # Class level logger method for includer class (base)
16
- def base.logger
17
- @logger ||= EasyLogging.logger_for(self)
18
- end
19
- end
20
-
21
- # Global, memoized, lazy initialized instance of a logger
22
- def self.logger_for(classname)
23
- @loggers[classname] ||= configure_logger_for(classname)
24
- end
25
-
26
- def self.configure_logger_for(classname)
27
- logger = Logger.new(STDOUT)
28
- logger.progname = classname
29
- logger
30
- end
31
-
32
- end
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
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.1.1
4
+ version: 0.2.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-04 00:00:00.000000000 Z
11
+ date: 2017-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler