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 +4 -4
- data/README.md +102 -104
- data/easy_logging.gemspec +26 -26
- data/lib/easy_logging/version.rb +3 -3
- data/lib/easy_logging.rb +43 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ec34fd51402cfc73189bc9f9abd0b61b889f5e4
|
4
|
+
data.tar.gz: d535f3bfe5bc2b9576a22451d5584787be92e175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
```
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
data/lib/easy_logging/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module EasyLogging
|
2
|
-
VERSION = "0.
|
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
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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.
|
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-
|
11
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|