logger_facade 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.rspec +1 -0
- data/.rvmrc.example +1 -0
- data/.travis.yml +20 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +54 -0
- data/LICENSE +21 -0
- data/README.md +151 -0
- data/Rakefile +2 -0
- data/lib/logger_facade/log.rb +46 -0
- data/lib/logger_facade/manager.rb +31 -0
- data/lib/logger_facade/plugins/console.rb +87 -0
- data/lib/logger_facade/plugins.rb +1 -0
- data/lib/logger_facade/version.rb +3 -0
- data/lib/logger_facade.rb +9 -0
- data/logger_facade.gemspec +29 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/log_spec.rb +55 -0
- data/spec/unit/manager_spec.rb +60 -0
- data/spec/unit/plugins/console_spec.rb +80 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a47f01542a6c0c29f55fb9f18b3964cea85cd436
|
4
|
+
data.tar.gz: 6545ed4009bda96bc5c63bea58b25f47807627a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5f6fee935a12743caf1590f5bc21d605a264ddf0af1e9ba9bffe7a6d2db8da71d126af1fd692463390da18f92959ffcff607232eebfcbf11b95877aa1bfd9a5
|
7
|
+
data.tar.gz: b3c0b2b40bc51dc1865ffb65c2d6c246cc3fc31ac873ae15595e3697e5e8b4327b46d23e570a0e8ccf3e5a1a07ba6a0c127a87e3a556e7246fc57e4c3669a251
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-f doc --color
|
data/.rvmrc.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 2.1.2@logger-facade --create
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache:
|
3
|
+
- bundler
|
4
|
+
- apt
|
5
|
+
rvm:
|
6
|
+
- 2.1.2
|
7
|
+
branches:
|
8
|
+
only:
|
9
|
+
- master
|
10
|
+
env:
|
11
|
+
global:
|
12
|
+
- DISPLAY=:99.0
|
13
|
+
before_install:
|
14
|
+
- gem install bundler --no-rdoc --no-ri 1>/dev/null
|
15
|
+
script:
|
16
|
+
- "bundle exec rspec"
|
17
|
+
addons:
|
18
|
+
code_climate:
|
19
|
+
repo_token:
|
20
|
+
secure: CeIbZfZ95Np4BIr2MxZauvwYwqxXWeGirTcA0uMAR32nlWx1045bxx5+4k9yuscsJV4z04mdq1EzfL5xt8C9iB1BmUCAQnv1jGEYf+w6dFGKcQqSsySk1xEag4yeFRe//Q0UsLbtI8kvYTdwjr52Dt2y2x6DFkl3GxizEQNhxbI=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
logger_facade (0.0.0)
|
5
|
+
hashie
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
bump (0.5.0)
|
11
|
+
codeclimate-test-reporter (0.3.0)
|
12
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
13
|
+
coderay (1.1.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
docile (1.1.5)
|
16
|
+
hashie (3.2.0)
|
17
|
+
method_source (0.8.2)
|
18
|
+
multi_json (1.10.1)
|
19
|
+
pry (0.10.0)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.8.1)
|
22
|
+
slop (~> 3.4)
|
23
|
+
rake (10.3.2)
|
24
|
+
rspec (3.0.0)
|
25
|
+
rspec-core (~> 3.0.0)
|
26
|
+
rspec-expectations (~> 3.0.0)
|
27
|
+
rspec-mocks (~> 3.0.0)
|
28
|
+
rspec-core (3.0.3)
|
29
|
+
rspec-support (~> 3.0.0)
|
30
|
+
rspec-expectations (3.0.3)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.0.0)
|
33
|
+
rspec-mocks (3.0.3)
|
34
|
+
rspec-support (~> 3.0.0)
|
35
|
+
rspec-support (3.0.3)
|
36
|
+
simplecov (0.9.0)
|
37
|
+
docile (~> 1.1.0)
|
38
|
+
multi_json
|
39
|
+
simplecov-html (~> 0.8.0)
|
40
|
+
simplecov-html (0.8.0)
|
41
|
+
slop (3.6.0)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bump
|
48
|
+
bundler (~> 1.6)
|
49
|
+
codeclimate-test-reporter
|
50
|
+
logger_facade!
|
51
|
+
pry
|
52
|
+
rake
|
53
|
+
rspec
|
54
|
+
simplecov
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Pedro Januário
|
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
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/pjanuario/logger-facade-ruby.svg?branch=master)](https://travis-ci.org/pjanuario/logger-facade-ruby)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/pjanuario/logger-facade-ruby.png)](https://codeclimate.com/github/pjanuario/logger-facade-ruby)
|
3
|
+
[![Coverage](http://img.shields.io/codeclimate/coverage/github/pjanuario/logger-facade-ruby.svg)](https://codeclimate.com/github/pjanuario/logger-facade-ruby)
|
4
|
+
[![Dependency Status](https://gemnasium.com/pjanuario/logger-facade-ruby.svg)](https://gemnasium.com/pjanuario/logger-facade-ruby)
|
5
|
+
|
6
|
+
# Logger Facade Ruby
|
7
|
+
|
8
|
+
[![version](https://badge.fury.io/rb/logger-facade-ruby.svg)](https://rubygems.org/gems/logger-facade)
|
9
|
+
|
10
|
+
|
11
|
+
Simple class library to work as logger facade.
|
12
|
+
|
13
|
+
This simple logger facade allows you to hook plugins to execute logging.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem ' logger_facade'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install logger_facade
|
28
|
+
|
29
|
+
## How to use it
|
30
|
+
|
31
|
+
Install it:
|
32
|
+
|
33
|
+
```
|
34
|
+
gem install logger_facade
|
35
|
+
```
|
36
|
+
|
37
|
+
Set up plugins
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'logger_facade'
|
41
|
+
|
42
|
+
# this is default config for Console plugin
|
43
|
+
config = {
|
44
|
+
level: :info,
|
45
|
+
time_format: '%y-%M-%d %H:%M:%S',
|
46
|
+
message_format: '%time | %level | %logger - %msg'
|
47
|
+
}
|
48
|
+
|
49
|
+
# configuration is optional in console plugin
|
50
|
+
plugin = LoggerFacade::Plugins::Console.new(config);
|
51
|
+
|
52
|
+
# hook plugin/s
|
53
|
+
LoggerFacade::Manager.use(plugin)
|
54
|
+
|
55
|
+
# obtain class logger
|
56
|
+
log = LoggerFacade::Manager.get_logger("Log Name")
|
57
|
+
|
58
|
+
# log
|
59
|
+
log.debug("something to log")
|
60
|
+
log.info("something to log in info")
|
61
|
+
|
62
|
+
# log exception directly
|
63
|
+
log.error(Exception.new("some caught exception"))
|
64
|
+
```
|
65
|
+
|
66
|
+
**NOTE**: Console plugin uses check [strftime](http://www.ruby-doc.org/core-2.1.2/Time.html#method-i-strftime) formats.
|
67
|
+
|
68
|
+
## Available plugins
|
69
|
+
* Console
|
70
|
+
* Airbrake (Will be developed soon)
|
71
|
+
* Elasticsearch (Will be developed soon)
|
72
|
+
|
73
|
+
** Do you need some other plugin?**
|
74
|
+
|
75
|
+
Feel free to create one and get in touch with me, that i will add it to this list.
|
76
|
+
|
77
|
+
## LoggerFacade::Manager Contract
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# register a plugin on logger
|
81
|
+
LoggerFacade::Manager.use(plugin)
|
82
|
+
# retrieve the list of plugin names
|
83
|
+
LoggerFacade::Manager.plugins()
|
84
|
+
# clean up the list of registered plugins
|
85
|
+
LoggerFacade::Manager.clearPlugins()
|
86
|
+
# retrieve a logger with the specified name
|
87
|
+
log = LoggerFacade::Manager.getLogger("Log Name")
|
88
|
+
```
|
89
|
+
|
90
|
+
## LoggerFacade::Log Contract
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
log.isDebug() # return if in debug or trace level
|
94
|
+
log.trace("trace something")
|
95
|
+
log.debug("debug something")
|
96
|
+
log.info("info something")
|
97
|
+
log.warn("warn something")
|
98
|
+
log.error("error something")
|
99
|
+
log.error(Exception.new('some caught exception'))
|
100
|
+
```
|
101
|
+
|
102
|
+
## LoggerFacade::Plugins
|
103
|
+
|
104
|
+
The plugins must follow this contract:
|
105
|
+
|
106
|
+
```
|
107
|
+
# plugin name
|
108
|
+
#name
|
109
|
+
|
110
|
+
#isDebug
|
111
|
+
#trace
|
112
|
+
#debug
|
113
|
+
#info
|
114
|
+
#warn
|
115
|
+
#error
|
116
|
+
```
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
1. Fork it
|
121
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
122
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
123
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
124
|
+
5. Create new Pull Request
|
125
|
+
|
126
|
+
## Bump versioning
|
127
|
+
|
128
|
+
We use [bump gem](https://github.com/gregorym/bump) to control gem versioning.
|
129
|
+
|
130
|
+
Bump Patch version
|
131
|
+
|
132
|
+
$ bump patch
|
133
|
+
|
134
|
+
Bump Minor version
|
135
|
+
|
136
|
+
$ bump minor
|
137
|
+
|
138
|
+
Bump Major version
|
139
|
+
|
140
|
+
$ bump major
|
141
|
+
|
142
|
+
## Running Specs
|
143
|
+
|
144
|
+
$ rspec
|
145
|
+
|
146
|
+
## Coverage Report
|
147
|
+
|
148
|
+
$ open ./coverage/index.html
|
149
|
+
|
150
|
+
## Credits
|
151
|
+
Shout out to @pjanuario.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module LoggerFacade
|
2
|
+
|
3
|
+
class Log
|
4
|
+
|
5
|
+
attr_reader :plugins, :name
|
6
|
+
|
7
|
+
def initialize(name, plugins)
|
8
|
+
@name = name
|
9
|
+
@plugins = plugins
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_debug
|
13
|
+
plugins.select { |p| p.is_debug }.size > 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def trace(message)
|
17
|
+
log(:trace, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def debug(message)
|
21
|
+
log(:debug, message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(message)
|
25
|
+
log(:info, message)
|
26
|
+
end
|
27
|
+
|
28
|
+
def warn(message)
|
29
|
+
log(:warn, message)
|
30
|
+
end
|
31
|
+
|
32
|
+
def error(message)
|
33
|
+
log(:error, message)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def log(level, message)
|
39
|
+
plugins.each do |plugin|
|
40
|
+
plugin.send(level, name, message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module LoggerFacade
|
2
|
+
|
3
|
+
class Manager
|
4
|
+
|
5
|
+
def self.use(plugin)
|
6
|
+
fail 'Invalid plugin argument' unless plugin
|
7
|
+
|
8
|
+
registered_plugins << plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.plugins
|
12
|
+
registered_plugins.map(&:name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.clear_plugins
|
16
|
+
@@plugins = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_logger(name)
|
20
|
+
LoggerFacade::Log.new(name, registered_plugins)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.registered_plugins
|
26
|
+
@@plugins ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module LoggerFacade::Plugins
|
4
|
+
|
5
|
+
class Console
|
6
|
+
|
7
|
+
attr_reader :config, :level, :name
|
8
|
+
|
9
|
+
def initialize(config = {})
|
10
|
+
defaults = {
|
11
|
+
level: :info,
|
12
|
+
time_format: '%y-%M-%d %H:%M:%S',
|
13
|
+
message_format: '%time | %level | %logger - %msg'
|
14
|
+
}
|
15
|
+
config = defaults.merge(config)
|
16
|
+
|
17
|
+
@config = Hashie::Mash.new(config)
|
18
|
+
@level = @config.level.to_sym
|
19
|
+
@name = "LoggerFacade::Plugins::Console"
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_debug
|
23
|
+
is_level_active(:debug)
|
24
|
+
end
|
25
|
+
|
26
|
+
def trace(logger, message)
|
27
|
+
log(:trace, message, logger)
|
28
|
+
end
|
29
|
+
|
30
|
+
def debug(logger, message)
|
31
|
+
log(:debug, message, logger)
|
32
|
+
end
|
33
|
+
|
34
|
+
def info(logger, message)
|
35
|
+
log(:info, message, logger)
|
36
|
+
end
|
37
|
+
|
38
|
+
def warn(logger, message)
|
39
|
+
log(:warn, message, logger)
|
40
|
+
end
|
41
|
+
|
42
|
+
def error(logger, message)
|
43
|
+
log(:error, message, logger)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def levels
|
49
|
+
{
|
50
|
+
trace: 0,
|
51
|
+
debug: 1,
|
52
|
+
info: 2,
|
53
|
+
warn: 3,
|
54
|
+
error: 4
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_level_active(log_level)
|
59
|
+
levels[log_level] >= levels[level]
|
60
|
+
end
|
61
|
+
|
62
|
+
def message(level, msg, logger)
|
63
|
+
outputMsg = msg
|
64
|
+
|
65
|
+
if msg.is_a? Exception
|
66
|
+
outputMsg = "#{msg.message}\n#{(msg.backtrace || []).join("\n")}"
|
67
|
+
end
|
68
|
+
|
69
|
+
formatedMessage = config.message_format
|
70
|
+
.gsub('%logger', logger.upcase)
|
71
|
+
.gsub('%time', Time.now.utc.strftime(config.time_format))
|
72
|
+
.gsub('%level', level.to_s.upcase)
|
73
|
+
.gsub('%pid', Process.pid.to_s)
|
74
|
+
.gsub('%msg', outputMsg)
|
75
|
+
|
76
|
+
return formatedMessage;
|
77
|
+
end
|
78
|
+
|
79
|
+
def log(log_level, message, logger)
|
80
|
+
return unless is_level_active(log_level)
|
81
|
+
|
82
|
+
Kernel.puts message(log_level, message, logger)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'plugins/console'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require './lib/logger_facade/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'logger_facade'
|
7
|
+
spec.version = LoggerFacade::VERSION
|
8
|
+
spec.authors = ["Pedro Januário"]
|
9
|
+
spec.email = ["prnjanuario@gmail.com"]
|
10
|
+
spec.description = %q{Logger Facade library}
|
11
|
+
spec.summary = %q{Logger Facade library}
|
12
|
+
spec.homepage = "https://github.com/pjanuario/logger-facade-ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'pry'
|
24
|
+
spec.add_development_dependency 'simplecov'
|
25
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
26
|
+
spec.add_development_dependency 'bump'
|
27
|
+
|
28
|
+
spec.add_dependency 'hashie'
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
else
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter '/spec/'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
$:.push '.'
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'pry'
|
15
|
+
require 'logger_facade'
|
16
|
+
|
17
|
+
Dir['spec/support/**/*.rb'].each &method(:require)
|
18
|
+
|
19
|
+
RSpec.configure do |c|
|
20
|
+
c.around(:each) do |example|
|
21
|
+
Timeout::timeout(2) {
|
22
|
+
example.run
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LoggerFacade::Log do
|
4
|
+
|
5
|
+
let(:plugin) { double('plugin').as_null_object }
|
6
|
+
|
7
|
+
subject { described_class.new('log', [plugin]) }
|
8
|
+
|
9
|
+
describe('#isDebug') do
|
10
|
+
|
11
|
+
context('when exists a plugin configured in debug levels') do
|
12
|
+
|
13
|
+
it('returns true') do
|
14
|
+
allow(plugin).to receive(:is_debug) { true }
|
15
|
+
expect(subject.is_debug).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context('when does not exists a plugin configured in debug levels') do
|
21
|
+
|
22
|
+
it('returns false') do
|
23
|
+
allow(plugin).to receive(:is_debug) { true }
|
24
|
+
expect(subject.is_debug).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context('when does not exists plugins') do
|
30
|
+
|
31
|
+
subject { described_class.new('log', []) }
|
32
|
+
|
33
|
+
it('returns false') do
|
34
|
+
expect(subject.is_debug).to be false
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
%w(trace debug info warn error).each do |level|
|
42
|
+
|
43
|
+
describe("##{level}") do
|
44
|
+
|
45
|
+
it("calls the plugin in #{level} level") do
|
46
|
+
message = "call with message"
|
47
|
+
expect(plugin).to receive(level.to_sym).with(subject.name, message)
|
48
|
+
subject.send(level.to_sym, message)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LoggerFacade::Manager do
|
4
|
+
|
5
|
+
let :plugin do
|
6
|
+
plugin = double('plugin').as_null_object
|
7
|
+
allow(plugin).to receive(:name) { "mock_plugin" }
|
8
|
+
plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) { described_class.clear_plugins }
|
12
|
+
|
13
|
+
describe('.use') do
|
14
|
+
|
15
|
+
it('register a plugin') do
|
16
|
+
described_class.use(plugin)
|
17
|
+
expect(described_class.plugins).to eq(['mock_plugin'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it('does not register nil plugin') do
|
21
|
+
expect { described_class.use(nil) }.to raise_exception
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
describe('.plugins') do
|
28
|
+
|
29
|
+
before(:each) { described_class.use(plugin) }
|
30
|
+
|
31
|
+
it('returns registered plugins name') do
|
32
|
+
expect(described_class.plugins).to eq(['mock_plugin'])
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
describe('.clear_plugins') do
|
39
|
+
|
40
|
+
before(:each) { described_class.use(plugin) }
|
41
|
+
|
42
|
+
it('removes all registered plugins') do
|
43
|
+
described_class.clear_plugins
|
44
|
+
expect(described_class.plugins).to eq([])
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
describe('.get_logger') do
|
51
|
+
|
52
|
+
it('returns a logger instance') do
|
53
|
+
log = described_class.get_logger('log')
|
54
|
+
expect(log).to be_truthy
|
55
|
+
expect(log.name).to eq('log')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LoggerFacade::Plugins::Console do
|
4
|
+
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
let(:time) { Time.new(1983, 01, 25, 13, 10, 01, '+00:00') }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
allow(Time).to receive(:now) { time }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe('#is_debug') do
|
14
|
+
|
15
|
+
it('returns true when log level lower than info') do
|
16
|
+
subject = described_class.new({ level: :debug })
|
17
|
+
expect(subject.is_debug).to be true
|
18
|
+
end
|
19
|
+
|
20
|
+
it('returns false when log level higher than debug') do
|
21
|
+
expect(subject.is_debug).to be false
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_level(lev)
|
27
|
+
levels = {
|
28
|
+
trace: 0,
|
29
|
+
debug: 1,
|
30
|
+
info: 2,
|
31
|
+
warn: 3,
|
32
|
+
error: 4
|
33
|
+
}
|
34
|
+
|
35
|
+
val = levels[lev.to_sym]
|
36
|
+
levels.select { |k,v| v > val }.keys.first
|
37
|
+
end
|
38
|
+
|
39
|
+
%w(trace debug info warn error).each do |level|
|
40
|
+
|
41
|
+
context("logging in #{level} level") do
|
42
|
+
subject { described_class.new({ level: level.to_sym }) }
|
43
|
+
|
44
|
+
context("when plugin log level lower or equal than #{level}") do
|
45
|
+
|
46
|
+
it("writes to stdout") do
|
47
|
+
message = "call with message"
|
48
|
+
expect(Kernel).to receive(:puts)
|
49
|
+
.with("83-10-25 13:10:01 | #{level.upcase} | NAME - call with message")
|
50
|
+
subject.send(level.to_sym, "name", message)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
unless level == 'error'
|
56
|
+
context("when plugin log level higher than #{level}") do
|
57
|
+
|
58
|
+
subject { described_class.new({ level: next_level(level) }) }
|
59
|
+
|
60
|
+
it("doesn't write to stdout") do
|
61
|
+
message = "call with message"
|
62
|
+
expect(Kernel).not_to receive(:puts)
|
63
|
+
subject.send(level.to_sym, "name", message)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
it('log an exception') do
|
74
|
+
error = Exception.new('test log')
|
75
|
+
expect(Kernel).to receive(:puts)
|
76
|
+
.with("83-10-25 13:10:01 | ERROR | NAME - test log\n")
|
77
|
+
subject.error("name", error)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logger_facade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro Januário
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-30 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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: codeclimate-test-reporter
|
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: bump
|
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'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hashie
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Logger Facade library
|
126
|
+
email:
|
127
|
+
- prnjanuario@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rvmrc.example"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- lib/logger_facade.rb
|
142
|
+
- lib/logger_facade/log.rb
|
143
|
+
- lib/logger_facade/manager.rb
|
144
|
+
- lib/logger_facade/plugins.rb
|
145
|
+
- lib/logger_facade/plugins/console.rb
|
146
|
+
- lib/logger_facade/version.rb
|
147
|
+
- logger_facade.gemspec
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/unit/log_spec.rb
|
150
|
+
- spec/unit/manager_spec.rb
|
151
|
+
- spec/unit/plugins/console_spec.rb
|
152
|
+
homepage: https://github.com/pjanuario/logger-facade-ruby
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.2.2
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Logger Facade library
|
176
|
+
test_files:
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/unit/log_spec.rb
|
179
|
+
- spec/unit/manager_spec.rb
|
180
|
+
- spec/unit/plugins/console_spec.rb
|