logification 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +27 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +14 -0
- data/lib/logification.rb +54 -0
- data/lib/logification/helpers.rb +2 -0
- data/lib/logification/helpers/logging_methods.rb +60 -0
- data/lib/logification/helpers/wrapper.rb +44 -0
- data/lib/logification/logger.rb +33 -0
- data/lib/logification/version.rb +3 -0
- data/logification.gemspec +30 -0
- data/spec/logification/helpers/logging_methods_spec.rb +48 -0
- data/spec/logification/helpers/wrapper_spec.rb +53 -0
- data/spec/logification/logger_spec.rb +93 -0
- data/spec/logification/version_spec.rb +13 -0
- data/spec/logification_spec.rb +27 -0
- data/spec/spec_helper.rb +102 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b78a70684aff415b31da4088bf37a56020a7ff4
|
4
|
+
data.tar.gz: 3e8d963b90d1e4893c6c6bedee305a8ef3d08d27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 915f983fd6f3d53d159818904fdd6dc2a71f623385cd3150a4bec04c2a5cd27910acf83e0ca9b8010963f14e645069f2648772f509df555c57f86cde3010cba6
|
7
|
+
data.tar.gz: 5107610bbb880daf11809e0724ffcd82b8bb0da2aaa61b8da2403c505b44ae042e9ed723b60c68aba6589e75efa86643eb2fde67e7d852cdf87ebc03fe5a9c56
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
todo.txt
|
24
|
+
.ruby-*
|
25
|
+
.DS_store
|
26
|
+
*.log
|
27
|
+
test.rb
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nirmit Patel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
Logification
|
2
|
+
============
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/logification.svg)](http://badge.fury.io/rb/logification) [![Build Status](https://travis-ci.org/NeMO84/logification.svg?branch=master)](https://travis-ci.org/NeMO84/logification) [![Dependency Status](https://gemnasium.com/NeMO84/logification.svg)](https://gemnasium.com/NeMO84/logification) [![Code Climate](https://codeclimate.com/github/NeMO84/logification/badges/gpa.svg)](https://codeclimate.com/github/NeMO84/logification) [![Test Coverage](https://codeclimate.com/github/NeMO84/logification/badges/coverage.svg)](https://codeclimate.com/github/NeMO84/logification)
|
5
|
+
|
6
|
+
Logification is an abstracted logging gem library. Its purpose is to simplyify and enhance logging. Some added benefits: wrapping, color coated output (terminal only) and more to come.
|
7
|
+
|
8
|
+
Logification's purpose is to enhance existing libraries by providing features on top of their general output. It currently makes an assumption that the base logging library supports the following levels debug, info, warn, error, fatal.
|
9
|
+
|
10
|
+
Logification has been integrated with the already very powerful Log4r. But future goals are to make it even less dependent on any specific logging library.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'logification'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install logification
|
25
|
+
|
26
|
+
## Sample Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require "logification"
|
30
|
+
|
31
|
+
# Nested logging (nested_tabbing is enabled by default)
|
32
|
+
Logification.logger.wrap("SomeTask", nested_tabbing: false) do |logger|
|
33
|
+
|
34
|
+
logger.debug "Working on task1"
|
35
|
+
logger.warn "Working on task2"
|
36
|
+
|
37
|
+
# The below output should be nested
|
38
|
+
logger.wrap("SomeSubTask") do |nested_logger|
|
39
|
+
nested_logger.error "Working on sub task1"
|
40
|
+
nested_logger.fatal "Working on sub task2"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Terminal output should be color coated
|
46
|
+
#=> 2014-09-08 18:19:14 INFO [logification] - Starting 'SomeTask':
|
47
|
+
#=> 2014-09-08 18:19:14 DEBU [logification] - Working on task1
|
48
|
+
#=> 2014-09-08 18:19:14 WARN [logification] - Working on task2
|
49
|
+
#=> 2014-09-08 18:19:14 INFO [logification] - Starting 'SomeSubTask':
|
50
|
+
#=> 2014-09-08 18:19:14 ERRO [logification] - Working on sub task1
|
51
|
+
#=> 2014-09-08 18:19:14 FATA [logification] - Working on sub task2
|
52
|
+
#=> 2014-09-08 18:19:14 INFO [logification] - Completed 'SomeSubTask' in 0.0s
|
53
|
+
#=> 2014-09-08 18:19:14 INFO [logification] - Completed 'SomeTask' in 0.0s
|
54
|
+
|
55
|
+
# Custom logging
|
56
|
+
# Assumes BasicLogger responds to above listed levels and 'level' method call
|
57
|
+
class BasicLogger
|
58
|
+
attr_accessor :level
|
59
|
+
def debug(msg); puts ["DEBUG", msg].join(" "); end
|
60
|
+
def info(msg); puts ["INFO ", msg].join(" "); end
|
61
|
+
def warn(msg); puts ["WARN ", msg].join(" "); end
|
62
|
+
def error(msg); puts ["ERROR", msg].join(" "); end
|
63
|
+
def fatal(msg); puts ["FATAL", msg].join(" "); end
|
64
|
+
end
|
65
|
+
|
66
|
+
logger = Logification::Logger.new(name: "myproject", base_logger: BasicLogger.new)
|
67
|
+
logger.debug "This should be color formatted now"
|
68
|
+
logger.wrap("ImagePostProcessing: 123", wrap_level: :debug) do |nested_logger|
|
69
|
+
begin
|
70
|
+
nested_logger.info "Image has been initialized"
|
71
|
+
sleep(1) # resize
|
72
|
+
nested_logger.warn "Image has been resized, but aspect ratio was not preserved"
|
73
|
+
sleep(1) # upload
|
74
|
+
nested_logger.fatal "Updated image has been uploaded"
|
75
|
+
ensure
|
76
|
+
nested_logger.error "A failure with the processing has happened"
|
77
|
+
end
|
78
|
+
nested_logger.fatal "This is a random fatal message"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Terminal ouptut should be color coated
|
82
|
+
#=> DEBUG This should be color formatted now
|
83
|
+
#=> DEBUG Starting 'ImagePostProcessing: 123':
|
84
|
+
#=> INFO Image has been initialized
|
85
|
+
#=> WARN Image has been resized, but aspect ratio was not preserved
|
86
|
+
#=> FATAL Updated image has been uploaded
|
87
|
+
#=> ERROR A failure with the processing has happened
|
88
|
+
#=> FATAL This is a random fatal message
|
89
|
+
#=> DEBUG Completed 'ImagePostProcessing: 123' in 2.001s
|
90
|
+
```
|
91
|
+
|
92
|
+
## TODO
|
93
|
+
|
94
|
+
- Update README
|
95
|
+
- Add error handling, logging should be conspicuous.
|
96
|
+
- Remove dependency on log4r
|
97
|
+
- Think up more TODO items
|
98
|
+
- Make log level colors configurable
|
99
|
+
- Improve testing by writing more micro functional tests
|
100
|
+
|
101
|
+
|
102
|
+
## Known Issues
|
103
|
+
|
104
|
+
TODO:
|
105
|
+
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
1. Fork it ( https://github.com/[my-github-username]/logification/fork )
|
110
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
113
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
desc "Start console mode w/ library loaded"
|
9
|
+
task :console do
|
10
|
+
require 'pry'
|
11
|
+
require_relative "lib/logification"
|
12
|
+
ARGV.clear
|
13
|
+
Pry.start
|
14
|
+
end
|
data/lib/logification.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "logification/version"
|
2
|
+
require "logification/helpers"
|
3
|
+
require "logification/logger"
|
4
|
+
|
5
|
+
# http://stackoverflow.com/questions/5799823/ruby-uninitialized-constant-log4rdebug-nameerror-problem/5800326#5800326
|
6
|
+
Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
|
7
|
+
|
8
|
+
module Logification
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
attr_accessor :logger
|
13
|
+
|
14
|
+
def logger
|
15
|
+
@logger ||= begin
|
16
|
+
Logification::Logger.new.tap do |l|
|
17
|
+
l.base_logger.level = translate_level(:debug)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def level=(lvl)
|
23
|
+
logger.base_logger.level = @level = translate_level(lvl)
|
24
|
+
end
|
25
|
+
|
26
|
+
def level
|
27
|
+
LOG4R_LEVEL_TRANSLATION_REVERSE[logger.base_logger.level]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
LOG4R_LEVEL_TRANSLATION = {
|
33
|
+
:debug => Log4r::DEBUG,
|
34
|
+
:info => Log4r::INFO,
|
35
|
+
:warn => Log4r::WARN,
|
36
|
+
:error => Log4r::ERROR,
|
37
|
+
:fatal => Log4r::FATAL
|
38
|
+
}
|
39
|
+
|
40
|
+
LOG4R_LEVEL_TRANSLATION_REVERSE = {
|
41
|
+
1 => :debug,
|
42
|
+
2 => :info,
|
43
|
+
3 => :warn,
|
44
|
+
4 => :error,
|
45
|
+
5 => :fatal
|
46
|
+
}
|
47
|
+
|
48
|
+
def translate_level(lvl)
|
49
|
+
LOG4R_LEVEL_TRANSLATION[lvl]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Logification
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
module LoggingMethods
|
6
|
+
|
7
|
+
TAB = " "
|
8
|
+
|
9
|
+
def debug(msg=nil)
|
10
|
+
msg = yield if block_given?
|
11
|
+
log_message(:debug, msg, :green)
|
12
|
+
end
|
13
|
+
|
14
|
+
def info(msg=nil)
|
15
|
+
msg = yield if block_given?
|
16
|
+
log_message(:info, msg, :cyan)
|
17
|
+
end
|
18
|
+
|
19
|
+
def warn(msg=nil)
|
20
|
+
msg = yield if block_given?
|
21
|
+
log_message(:warn, msg, :yellow)
|
22
|
+
end
|
23
|
+
|
24
|
+
def error(msg=nil)
|
25
|
+
msg = yield if block_given?
|
26
|
+
log_message(:error, msg, :red)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fatal(msg=nil)
|
30
|
+
msg = yield if block_given?
|
31
|
+
log_message(:fatal, msg, :magenta)
|
32
|
+
end
|
33
|
+
|
34
|
+
def is_nested?
|
35
|
+
not nested_count.nil? and nested_count > 0
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def log_message(type, msg, color)
|
41
|
+
msg = messagify(msg)
|
42
|
+
base_logger.send(type, msg.to_s.send(color))
|
43
|
+
msg
|
44
|
+
end
|
45
|
+
|
46
|
+
def messagify(msg)
|
47
|
+
tabify(msg)
|
48
|
+
end
|
49
|
+
|
50
|
+
def tabify(msg)
|
51
|
+
return msg unless is_nested?
|
52
|
+
tab = TAB * nested_count # tab = 4 spaces
|
53
|
+
tab + msg
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Logification
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
module Wrapper
|
6
|
+
|
7
|
+
def wrap(name, options={})
|
8
|
+
settings = base_options.merge!(options)
|
9
|
+
settings.merge!(name: name)
|
10
|
+
self.send(settings[:wrap_level], start_message(settings))
|
11
|
+
nested_logger = self.dup
|
12
|
+
nested_logger.nested_count = self.nested_count+1 if settings[:nested_tabbing]
|
13
|
+
block_response = yield(nested_logger) if block_given?
|
14
|
+
self.send(settings[:wrap_level], end_message(settings))
|
15
|
+
block_response
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def base_options
|
21
|
+
{
|
22
|
+
nested_tabbing: true,
|
23
|
+
wrap_level: :info,
|
24
|
+
start_time: Time.now
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def start_message(options={})
|
29
|
+
options[:start_message] || "Starting '#{options[:name]}':"
|
30
|
+
end
|
31
|
+
|
32
|
+
def end_message(options={})
|
33
|
+
options[:end_message] || summary_message(options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def summary_message(options={})
|
37
|
+
"Completed '#{options[:name]}' in #{(Time.now - options[:start_time]).round(3)}s"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "log4r"
|
3
|
+
|
4
|
+
module Logification
|
5
|
+
|
6
|
+
class Logger
|
7
|
+
|
8
|
+
attr_accessor :base_logger
|
9
|
+
attr_accessor :nested_count
|
10
|
+
|
11
|
+
include Helpers::LoggingMethods
|
12
|
+
include Helpers::Wrapper
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
name = options[:name] || "logification"
|
16
|
+
@base_logger = options[:base_logger] || default_logger(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_logger(name)
|
20
|
+
Log4r::Logger.new(name).tap do |l|
|
21
|
+
l.outputters = Log4r::Outputter.stdout.tap do |o|
|
22
|
+
o.formatter = Log4r::PatternFormatter.new(pattern: "%d %.04l [%C] - %M")
|
23
|
+
end
|
24
|
+
l.level = Log4r::DEBUG
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def nested_count
|
29
|
+
@nested_count ||= 0
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logification/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logification"
|
8
|
+
spec.version = Logification::VERSION
|
9
|
+
spec.authors = ["Nirmit Patel"]
|
10
|
+
spec.email = ["nirmit@patelify.com"]
|
11
|
+
spec.summary = %q{Encourage logging by simplifiying it.}
|
12
|
+
spec.description = %q{Logging made simple}
|
13
|
+
spec.homepage = "http://github.com/patelify/logification"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
|
+
spec.add_development_dependency "simplecov", "~> 0.7"
|
26
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
|
27
|
+
|
28
|
+
spec.add_dependency "log4r", "~> 1.1"
|
29
|
+
spec.add_dependency "colorize", "~> 0.7"
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
describe Logification::Helpers::LoggingMethods do
|
2
|
+
|
3
|
+
let(:klass) {
|
4
|
+
class LoggingKlass
|
5
|
+
include Logification::Helpers::LoggingMethods
|
6
|
+
end
|
7
|
+
LoggingKlass
|
8
|
+
}
|
9
|
+
|
10
|
+
subject(:instance) { klass.new }
|
11
|
+
|
12
|
+
it "#debug" do
|
13
|
+
expect(instance.public_methods.include?(:debug)).to eql(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "#info" do
|
17
|
+
expect(instance.public_methods.include?(:info)).to eql(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#warn" do
|
21
|
+
expect(instance.public_methods.include?(:warn)).to eql(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#error" do
|
25
|
+
expect(instance.public_methods.include?(:error)).to eql(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#fatal" do
|
29
|
+
expect(instance.public_methods.include?(:fatal)).to eql(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#is_nested?" do
|
33
|
+
expect(instance.public_methods.include?(:is_nested?)).to eql(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#log_message (private)" do
|
37
|
+
expect(instance.private_methods.include?(:log_message)).to eql(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#messagify (private)" do
|
41
|
+
expect(instance.private_methods.include?(:messagify)).to eql(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#tabify (private)" do
|
45
|
+
expect(instance.private_methods.include?(:tabify)).to eql(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
describe Logification::Helpers::Wrapper do
|
2
|
+
|
3
|
+
let(:klass) {
|
4
|
+
class LoggingKlass
|
5
|
+
attr_accessor :base_logger, :nested_count
|
6
|
+
include Logification::Helpers::Wrapper
|
7
|
+
def initialize
|
8
|
+
@base_logger = Log4r::Logger.new(self.class.to_s)
|
9
|
+
@nested_count = 0
|
10
|
+
end
|
11
|
+
end
|
12
|
+
LoggingKlass
|
13
|
+
}
|
14
|
+
|
15
|
+
subject(:instance) { klass.new }
|
16
|
+
|
17
|
+
it "#wrap" do
|
18
|
+
expect(instance.public_methods.include?(:wrap)).to eql(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "#base_options (private)" do
|
22
|
+
expect(instance.private_methods.include?(:base_options)).to eql(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#start_message (private)" do
|
26
|
+
expect(instance.private_methods.include?(:start_message)).to eql(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#end_message (private)" do
|
30
|
+
expect(instance.private_methods.include?(:end_message)).to eql(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "#summary_message (private)" do
|
34
|
+
expect(instance.private_methods.include?(:summary_message)).to eql(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "wrap" do
|
38
|
+
|
39
|
+
it "basic" do
|
40
|
+
expect{instance.wrap("test")}.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "custom wrap level" do
|
44
|
+
expect{instance.wrap("test", level: :error)}.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "no nesting" do
|
48
|
+
expect{instance.wrap("test", nested_tabbing: false)}.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
describe Logification::Logger do
|
2
|
+
|
3
|
+
subject {
|
4
|
+
l = Logification::Logger.new(name: "test")
|
5
|
+
l.base_logger.outputters = []
|
6
|
+
l
|
7
|
+
}
|
8
|
+
|
9
|
+
describe "with message paramater" do
|
10
|
+
|
11
|
+
let(:message) { "Test message" }
|
12
|
+
|
13
|
+
it "#debug(message)" do
|
14
|
+
expect(subject.debug(message)).to eql(message)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#info(message)" do
|
18
|
+
expect(subject.info(message)).to eql(message)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "#warn(message)" do
|
22
|
+
expect(subject.warn(message)).to eql(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#error(message)" do
|
26
|
+
expect(subject.error(message)).to eql(message)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#fatal(message)" do
|
30
|
+
expect(subject.fatal(message)).to eql(message)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "with message block" do
|
36
|
+
|
37
|
+
let(:message) { "Test message" }
|
38
|
+
|
39
|
+
it "#debug(message)" do
|
40
|
+
expect(subject.debug{message}).to eql(message)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#info(message)" do
|
44
|
+
expect(subject.info{message}).to eql(message)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "#warn(message)" do
|
48
|
+
expect(subject.warn{message}).to eql(message)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#error(message)" do
|
52
|
+
expect(subject.error{message}).to eql(message)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#fatal(message)" do
|
56
|
+
expect(subject.fatal{message}).to eql(message)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "with nesting" do
|
62
|
+
|
63
|
+
let(:message) { "Test message" }
|
64
|
+
let(:tabbed_message) { Logification::Logger::TAB + message }
|
65
|
+
|
66
|
+
it "#debug(message)" do
|
67
|
+
subject.nested_count = 1
|
68
|
+
expect(subject.debug{message}).to eql(tabbed_message)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "#info(message)" do
|
72
|
+
subject.nested_count = 1
|
73
|
+
expect(subject.info{message}).to eql(tabbed_message)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "#warn(message)" do
|
77
|
+
subject.nested_count = 1
|
78
|
+
expect(subject.warn{message}).to eql(tabbed_message)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "#error(message)" do
|
82
|
+
subject.nested_count = 1
|
83
|
+
expect(subject.error{message}).to eql(tabbed_message)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "#fatal(message)" do
|
87
|
+
subject.nested_count = 1
|
88
|
+
expect(subject.fatal{message}).to eql(tabbed_message)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe Logification do
|
2
|
+
|
3
|
+
it ".logger" do
|
4
|
+
expect{subject.logger}.not_to raise_error
|
5
|
+
end
|
6
|
+
|
7
|
+
it ".logger should return a by default logger class" do
|
8
|
+
expect(subject.logger.class).to eql(Logification::Logger)
|
9
|
+
end
|
10
|
+
|
11
|
+
it ".logger=" do
|
12
|
+
saved_logger = subject.logger
|
13
|
+
subject.logger = Log4r::Logger.new("test")
|
14
|
+
expect(subject.logger.class).to eql(Log4r::Logger)
|
15
|
+
subject.logger = saved_logger
|
16
|
+
end
|
17
|
+
|
18
|
+
it ".level" do
|
19
|
+
expect{subject.level}.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it ".level=" do
|
23
|
+
subject.level = :debug
|
24
|
+
expect(subject.level).to eql(:debug)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
|
18
|
+
require 'pry' if ENV["PRY"]
|
19
|
+
|
20
|
+
if ENV["CODECLIMATE"]
|
21
|
+
require "codeclimate-test-reporter"
|
22
|
+
CodeClimate::TestReporter.start
|
23
|
+
else
|
24
|
+
require 'simplecov'
|
25
|
+
SimpleCov.start
|
26
|
+
end
|
27
|
+
|
28
|
+
require_relative "../lib/logification"
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
# rspec-expectations config goes here. You can use an alternate
|
32
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
33
|
+
# assertions if you prefer.
|
34
|
+
config.expect_with :rspec do |expectations|
|
35
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
36
|
+
# and `failure_message` of custom matchers include text for helper methods
|
37
|
+
# defined using `chain`, e.g.:
|
38
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
39
|
+
# # => "be bigger than 2 and smaller than 4"
|
40
|
+
# ...rather than:
|
41
|
+
# # => "be bigger than 2"
|
42
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
46
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
47
|
+
config.mock_with :rspec do |mocks|
|
48
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
49
|
+
# a real object. This is generally recommended, and will default to
|
50
|
+
# `true` in RSpec 4.
|
51
|
+
mocks.verify_partial_doubles = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# The settings below are suggested to provide a good initial experience
|
55
|
+
# with RSpec, but feel free to customize to your heart's content.
|
56
|
+
=begin
|
57
|
+
# These two settings work together to allow you to limit a spec run
|
58
|
+
# to individual examples or groups you care about by tagging them with
|
59
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
60
|
+
# get run.
|
61
|
+
config.filter_run :focus
|
62
|
+
config.run_all_when_everything_filtered = true
|
63
|
+
|
64
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
65
|
+
# For more details, see:
|
66
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
67
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
68
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
69
|
+
config.disable_monkey_patching!
|
70
|
+
|
71
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
72
|
+
# be too noisy due to issues in dependencies.
|
73
|
+
config.warnings = true
|
74
|
+
|
75
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
76
|
+
# file, and it's useful to allow more verbose output when running an
|
77
|
+
# individual spec file.
|
78
|
+
if config.files_to_run.one?
|
79
|
+
# Use the documentation formatter for detailed output,
|
80
|
+
# unless a formatter has already been configured
|
81
|
+
# (e.g. via a command-line flag).
|
82
|
+
config.default_formatter = 'doc'
|
83
|
+
end
|
84
|
+
|
85
|
+
# Print the 10 slowest examples and example groups at the
|
86
|
+
# end of the spec run, to help surface which specs are running
|
87
|
+
# particularly slow.
|
88
|
+
config.profile_examples = 10
|
89
|
+
|
90
|
+
# Run specs in random order to surface order dependencies. If you find an
|
91
|
+
# order dependency and want to debug it, you can fix the order by providing
|
92
|
+
# the seed, which is printed after each run.
|
93
|
+
# --seed 1234
|
94
|
+
config.order = :random
|
95
|
+
|
96
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
97
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
98
|
+
# test failures related to randomization by passing the same `--seed` value
|
99
|
+
# as the one that triggered the failure.
|
100
|
+
Kernel.srand config.seed
|
101
|
+
=end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nirmit Patel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-09 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: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
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.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
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.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
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.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: log4r
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: colorize
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.7'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.7'
|
125
|
+
description: Logging made simple
|
126
|
+
email:
|
127
|
+
- nirmit@patelify.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- lib/logification.rb
|
140
|
+
- lib/logification/helpers.rb
|
141
|
+
- lib/logification/helpers/logging_methods.rb
|
142
|
+
- lib/logification/helpers/wrapper.rb
|
143
|
+
- lib/logification/logger.rb
|
144
|
+
- lib/logification/version.rb
|
145
|
+
- logification.gemspec
|
146
|
+
- spec/logification/helpers/logging_methods_spec.rb
|
147
|
+
- spec/logification/helpers/wrapper_spec.rb
|
148
|
+
- spec/logification/logger_spec.rb
|
149
|
+
- spec/logification/version_spec.rb
|
150
|
+
- spec/logification_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
homepage: http://github.com/patelify/logification
|
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: Encourage logging by simplifiying it.
|
176
|
+
test_files:
|
177
|
+
- spec/logification/helpers/logging_methods_spec.rb
|
178
|
+
- spec/logification/helpers/wrapper_spec.rb
|
179
|
+
- spec/logification/logger_spec.rb
|
180
|
+
- spec/logification/version_spec.rb
|
181
|
+
- spec/logification_spec.rb
|
182
|
+
- spec/spec_helper.rb
|