semantic_logger 2.19.0 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/semantic_logger/loggable.rb +10 -54
- data/lib/semantic_logger/version.rb +1 -1
- data/test/loggable_test.rb +34 -0
- 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: 141016c8a502a158974b0dfe589a90b5cd650826
|
4
|
+
data.tar.gz: 09cb7afdf37afe6280098b01f7257c8a21b5995e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f734075af2a306b37560903beb0d0003f912706f6d68446914832cbb76a404c7017dd536c587eb155309a1128ebf328719f33c727b0ca129d03d2bea8f6fa21
|
7
|
+
data.tar.gz: a96ffd5c36c47e4e7787dc53970dafe092203f6e717f6aba4289217b45e14b1e36317151dcbe2af60178e78d3266ed92f23bd3f7ba6c39d1592d5fbd37794458
|
@@ -29,65 +29,21 @@ module SemanticLogger
|
|
29
29
|
|
30
30
|
def self.included(base)
|
31
31
|
base.class_eval do
|
32
|
+
# Returns [SemanticLogger::Logger] class level logger
|
32
33
|
def self.logger
|
33
34
|
@semantic_logger ||= SemanticLogger[self]
|
34
35
|
end
|
35
|
-
end
|
36
|
-
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
37
|
+
# Returns [SemanticLogger::Logger] instance level logger
|
38
|
+
def logger
|
39
|
+
@semantic_logger ||= self.class.logger
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# For example, server or host_name that the class instance is using.
|
50
|
-
#
|
51
|
-
# Example:
|
52
|
-
# require 'semantic_logger'
|
53
|
-
# SemanticLogger.default_level = :debug
|
54
|
-
# SemanticLogger.add_appender(STDOUT)
|
55
|
-
#
|
56
|
-
# class MyClass
|
57
|
-
# include SemanticLogger::Loggable
|
58
|
-
#
|
59
|
-
# def self.my_name=(my_name)
|
60
|
-
# # Use class level logger that only logs class name
|
61
|
-
# logger.info "My name is changed to #{my_name}"
|
62
|
-
#
|
63
|
-
# @@my_name = my_name
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# def initialize(host_name)
|
67
|
-
# # Add host_name to every log entry in this logging instance
|
68
|
-
# self.logger = SemanticLogger["#{self.class.name} [#{host_name}]"]
|
69
|
-
#
|
70
|
-
# logger.info "Started server"
|
71
|
-
# end
|
72
|
-
#
|
73
|
-
# def check
|
74
|
-
# logger.debug "Checking..."
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# MyClass.my_name = "Joe"
|
79
|
-
#
|
80
|
-
# mine = MyClass.new('server.com')
|
81
|
-
# mine.check
|
82
|
-
#
|
83
|
-
# # Generates the following log output:
|
84
|
-
#
|
85
|
-
# 2013-04-02 15:08:42.368574 I [37279:70198560687720] MyClass -- My name is changed to Joe
|
86
|
-
# 2013-04-02 15:08:42.369934 I [37279:70198560687720] MyClass [server.com] -- Started server
|
87
|
-
# 2013-04-02 15:08:42.371171 D [37279:70198560687720] MyClass [server.com] -- Checking...
|
88
|
-
#
|
89
|
-
def logger=(logger)
|
90
|
-
@semantic_logger = logger
|
42
|
+
# Replace instance level logger
|
43
|
+
def logger=(logger)
|
44
|
+
@semantic_logger = logger
|
45
|
+
end
|
46
|
+
end
|
91
47
|
end
|
92
48
|
|
93
49
|
end
|
data/test/loggable_test.rb
CHANGED
@@ -8,11 +8,25 @@ end
|
|
8
8
|
# Unit Test for SemanticLogger::Appender::File
|
9
9
|
#
|
10
10
|
class AppenderFileTest < Minitest::Test
|
11
|
+
module Perform
|
12
|
+
def perform
|
13
|
+
logger.info 'perform'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
11
17
|
class Base
|
12
18
|
include SemanticLogger::Loggable
|
19
|
+
include Perform
|
20
|
+
end
|
21
|
+
|
22
|
+
module Process
|
23
|
+
def process
|
24
|
+
logger.info 'process'
|
25
|
+
end
|
13
26
|
end
|
14
27
|
|
15
28
|
class Subclass < Base
|
29
|
+
include Process
|
16
30
|
end
|
17
31
|
|
18
32
|
describe SemanticLogger::Loggable do
|
@@ -36,6 +50,26 @@ class AppenderFileTest < Minitest::Test
|
|
36
50
|
refute_equal child_logger, base.logger
|
37
51
|
assert_equal child_logger.object_id, subclass.logger.object_id
|
38
52
|
end
|
53
|
+
|
54
|
+
it 'should allow mixins to call parent logger' do
|
55
|
+
base = Base.new
|
56
|
+
base.perform
|
57
|
+
called = false
|
58
|
+
Base.logger.stub(:info, -> description { called = true if description == 'perform' }) do
|
59
|
+
base.perform
|
60
|
+
end
|
61
|
+
assert called, 'Did not call the correct logger'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should allow child mixins to call parent logger' do
|
65
|
+
subclass = Subclass.new
|
66
|
+
subclass.process
|
67
|
+
called = false
|
68
|
+
Subclass.logger.stub(:info, -> description { called = true if description == 'process' }) do
|
69
|
+
subclass.process
|
70
|
+
end
|
71
|
+
assert called, 'Did not call the correct logger'
|
72
|
+
end
|
39
73
|
end
|
40
74
|
|
41
75
|
describe 'logger' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|