logification 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logification.rb +3 -28
- data/lib/logification/helpers/logging_methods.rb +10 -5
- data/lib/logification/helpers/wrapper.rb +1 -1
- data/lib/logification/logger.rb +45 -5
- data/lib/logification/version.rb +1 -1
- data/spec/logification/helpers/logging_methods_spec.rb +24 -10
- data/spec/logification/logger_spec.rb +37 -3
- 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: 2481cd03cc8ad1ed7e938be6ffc7a2afdc0f0ded
|
4
|
+
data.tar.gz: 5f4fd772e9eaf73c9b29780b7f3fd179da9928ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3429471d1a9711d8a35cee58e373ec9d1c1843281cb80a5da1f97e2dd30e14f7ee0f8a9d54ff43b5d6381f508e6c0a1d73135b2866196ccffce9a172966f190f
|
7
|
+
data.tar.gz: 6b185f9bea0655740f5ca5bbc8cc7dc8c3586673dcd0db3e5afa21b47079bb15849e17ce6d78a0371de218a4638ca2e939cb09f511942842686b8c572d53b3b0
|
data/lib/logification.rb
CHANGED
@@ -2,9 +2,6 @@ require "logification/version"
|
|
2
2
|
require "logification/helpers"
|
3
3
|
require "logification/logger"
|
4
4
|
|
5
|
-
# http://stackoverflow.com/questions/5799823/ruby-uninitialized-constant-log4rdebug-nameerror-problem/5800326#5800326
|
6
|
-
Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
|
7
|
-
|
8
5
|
module Logification
|
9
6
|
|
10
7
|
class << self
|
@@ -14,39 +11,17 @@ module Logification
|
|
14
11
|
def logger
|
15
12
|
@logger ||= begin
|
16
13
|
Logification::Logger.new.tap do |l|
|
17
|
-
l.
|
14
|
+
l.level = :debug
|
18
15
|
end
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
19
|
def level=(lvl)
|
23
|
-
logger.
|
20
|
+
logger.level = lvl
|
24
21
|
end
|
25
22
|
|
26
23
|
def level
|
27
|
-
|
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]
|
24
|
+
logger.level
|
50
25
|
end
|
51
26
|
|
52
27
|
end
|
@@ -31,10 +31,6 @@ module Logification
|
|
31
31
|
log_message(:fatal, msg, :magenta)
|
32
32
|
end
|
33
33
|
|
34
|
-
def is_nested?
|
35
|
-
not nested_count.nil? and nested_count > 0
|
36
|
-
end
|
37
|
-
|
38
34
|
private
|
39
35
|
|
40
36
|
def log_message(type, msg, color)
|
@@ -44,15 +40,24 @@ module Logification
|
|
44
40
|
end
|
45
41
|
|
46
42
|
def messagify(msg)
|
43
|
+
if msg.is_a?(Exception)
|
44
|
+
exception = msg
|
45
|
+
error_message = "Caught #{exception.class}: #{exception.message}"
|
46
|
+
msg = [error_message, exception.backtrace].join("\n")
|
47
|
+
end
|
47
48
|
tabify(msg)
|
48
49
|
end
|
49
50
|
|
50
51
|
def tabify(msg)
|
51
52
|
return msg unless is_nested?
|
52
|
-
tab = TAB * nested_count # tab = 4 spaces
|
53
|
+
tab = TAB * self.nested_count # tab = 4 spaces
|
53
54
|
tab + msg
|
54
55
|
end
|
55
56
|
|
57
|
+
def is_nested?
|
58
|
+
not self.nested_count.nil? and self.nested_count > 0
|
59
|
+
end
|
60
|
+
|
56
61
|
end
|
57
62
|
|
58
63
|
end
|
@@ -8,7 +8,7 @@ module Logification
|
|
8
8
|
settings = base_options.merge!(options)
|
9
9
|
settings.merge!(name: name)
|
10
10
|
self.send(settings[:wrap_level], start_message(settings))
|
11
|
-
nested_logger = self.
|
11
|
+
nested_logger = self.clone
|
12
12
|
nested_logger.nested_count = self.nested_count+1 if settings[:nested_tabbing]
|
13
13
|
block_response = yield(nested_logger) if block_given?
|
14
14
|
self.send(settings[:wrap_level], end_message(settings))
|
data/lib/logification/logger.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
require "colorize"
|
2
2
|
require "log4r"
|
3
3
|
|
4
|
+
# http://stackoverflow.com/questions/5799823/ruby-uninitialized-constant-log4rdebug-nameerror-problem/5800326#5800326
|
5
|
+
Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
|
6
|
+
|
4
7
|
module Logification
|
5
8
|
|
6
9
|
class Logger
|
7
10
|
|
8
|
-
attr_accessor :base_logger
|
9
|
-
attr_accessor :nested_count
|
11
|
+
attr_accessor :name, :base_logger, :nested_count
|
10
12
|
|
11
13
|
include Helpers::LoggingMethods
|
12
14
|
include Helpers::Wrapper
|
13
15
|
|
14
16
|
def initialize(options={})
|
15
|
-
name = options[:name] || "logification"
|
16
|
-
|
17
|
+
self.name = options[:name] || "logification"
|
18
|
+
self.base_logger = options[:base_logger] || default_logger(@name)
|
19
|
+
self.nested_count = options[:nested_count] || 0
|
20
|
+
self.level = options[:level] || :debug
|
17
21
|
end
|
18
22
|
|
19
23
|
def default_logger(name)
|
@@ -21,7 +25,7 @@ module Logification
|
|
21
25
|
l.outputters = Log4r::Outputter.stdout.tap do |o|
|
22
26
|
o.formatter = Log4r::PatternFormatter.new(pattern: "%d %.04l [%C] - %M")
|
23
27
|
end
|
24
|
-
l.level =
|
28
|
+
l.level = translate_level(:debug)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -29,5 +33,41 @@ module Logification
|
|
29
33
|
@nested_count ||= 0
|
30
34
|
end
|
31
35
|
|
36
|
+
def level
|
37
|
+
LOG4R_LEVEL_TRANSLATION.key(base_logger.level)
|
38
|
+
end
|
39
|
+
|
40
|
+
def level=(value)
|
41
|
+
base_logger.level = translate_level(value)
|
42
|
+
@level = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def duplicate(name, options={})
|
46
|
+
settings = current_settings.merge(options)
|
47
|
+
self.class.new(settings.merge(name: name))
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def current_settings
|
53
|
+
{
|
54
|
+
name: self.name,
|
55
|
+
level: self.level,
|
56
|
+
nested_count: self.nested_count
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
LOG4R_LEVEL_TRANSLATION = {
|
61
|
+
:debug => 1,
|
62
|
+
:info => 2,
|
63
|
+
:warn => 3,
|
64
|
+
:error => 4,
|
65
|
+
:fatal => 5
|
66
|
+
}
|
67
|
+
|
68
|
+
def translate_level(lvl)
|
69
|
+
LOG4R_LEVEL_TRANSLATION[lvl.to_s.to_sym]
|
70
|
+
end
|
71
|
+
|
32
72
|
end
|
33
73
|
end
|
data/lib/logification/version.rb
CHANGED
@@ -7,42 +7,56 @@ describe Logification::Helpers::LoggingMethods do
|
|
7
7
|
LoggingKlass
|
8
8
|
}
|
9
9
|
|
10
|
-
subject(:
|
10
|
+
subject(:subject) { klass.new }
|
11
11
|
|
12
12
|
it "#debug" do
|
13
|
-
expect(
|
13
|
+
expect(subject.public_methods.include?(:debug)).to eql(true)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "#info" do
|
17
|
-
expect(
|
17
|
+
expect(subject.public_methods.include?(:info)).to eql(true)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "#warn" do
|
21
|
-
expect(
|
21
|
+
expect(subject.public_methods.include?(:warn)).to eql(true)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "#error" do
|
25
|
-
expect(
|
25
|
+
expect(subject.public_methods.include?(:error)).to eql(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "#fatal" do
|
29
|
-
expect(
|
29
|
+
expect(subject.public_methods.include?(:fatal)).to eql(true)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "#is_nested?" do
|
33
|
-
expect(
|
33
|
+
expect(subject.private_methods.include?(:is_nested?)).to eql(true)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "#log_message (private)" do
|
37
|
-
expect(
|
37
|
+
expect(subject.private_methods.include?(:log_message)).to eql(true)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "#messagify (private)" do
|
41
|
-
expect(
|
41
|
+
expect(subject.private_methods.include?(:messagify)).to eql(true)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "#tabify (private)" do
|
45
|
-
expect(
|
45
|
+
expect(subject.private_methods.include?(:tabify)).to eql(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "exception logging" do
|
49
|
+
|
50
|
+
subject {
|
51
|
+
Logification::Logger.new(name: "test").tap do |l|
|
52
|
+
l.base_logger.outputters = []
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
it "should log exceptions" do
|
57
|
+
expect{subject.error StandardError.new("expected")}.not_to raise_error
|
58
|
+
end
|
59
|
+
|
46
60
|
end
|
47
61
|
|
48
62
|
end
|
@@ -1,11 +1,33 @@
|
|
1
1
|
describe Logification::Logger do
|
2
2
|
|
3
3
|
subject {
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
Logification::Logger.new(name: "test").tap do |l|
|
5
|
+
l.base_logger.outputters = []
|
6
|
+
end
|
7
7
|
}
|
8
8
|
|
9
|
+
describe "settings" do
|
10
|
+
|
11
|
+
it "#level" do
|
12
|
+
expect{subject.level}.not_to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "#level=" do
|
16
|
+
subject.level = :debug
|
17
|
+
expect(subject.level).to eql(:debug)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#nested_count" do
|
21
|
+
expect(subject.nested_count).to eql(0)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#nested_count incremented" do
|
25
|
+
expect(subject.nested_count+=1).to eql(1)
|
26
|
+
subject.nested_count = 0
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
9
31
|
describe "with message paramater" do
|
10
32
|
|
11
33
|
let(:message) { "Test message" }
|
@@ -90,4 +112,16 @@ describe Logification::Logger do
|
|
90
112
|
|
91
113
|
end
|
92
114
|
|
115
|
+
describe "helper methods" do
|
116
|
+
|
117
|
+
it "#duplicate value" do
|
118
|
+
expect(subject.duplicate("duplicated")).not_to be_nil
|
119
|
+
end
|
120
|
+
|
121
|
+
it "#duplicate class" do
|
122
|
+
expect(subject.duplicate("duplicated").class).to eql(Logification::Logger)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
93
127
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nirmit Patel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|