protobuf 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 6806ad95dd3051a54c6bcae3940287187fd50239
4
- data.tar.gz: 326e902f6a3c9c64cc5a40b60562a04536d4e37d
5
- SHA512:
6
- metadata.gz: 22f3ac751be365b4d3a2efc6e14d2e9706049557558dae209b3c0abd0d9487b4f80c9abce743c6110721a0f1940f94c6635b7869559b8923a275e8ae2f05edaf
7
- data.tar.gz: e2b52a93261a2577ab260afefb1ab1eea6263a9a2ad8caac31a3058253c5bf55b042403b70901c8202c276302d6270f04bf1d2d72a212c2512f4728da82588e8
@@ -1,86 +0,0 @@
1
- require 'logger'
2
-
3
- module Protobuf
4
- class Logger < ::Logger
5
-
6
- class << self
7
- attr_accessor :file, :level
8
-
9
- # Stub out the log methods for Protobuf::Logger as singleton methods
10
- [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m|
11
- define_method(m) do |*params, &block|
12
- instance && instance.__send__(m, *params, &block)
13
- end
14
- end
15
- end
16
-
17
- # One-line file/level configuration
18
- def self.configure(options)
19
- self.file = options.fetch(:file, false)
20
- self.level = options.fetch(:level, false)
21
- end
22
-
23
- # Use to reset the instance
24
- def self.reset_device!
25
- self.file = self.level = @__instance = nil
26
- end
27
-
28
- # Singleton instance
29
- def self.instance
30
- @__instance ||= begin
31
- log = nil
32
-
33
- if @file && @level
34
- log = new(self.file)
35
- log.level = self.level
36
- end
37
-
38
- log
39
- end
40
- end
41
-
42
- #
43
- # LogMethods module for log method including, e.g.:
44
- #
45
- # class MyClass
46
- # include Protobuf::Logger::LogMethods
47
- # ...
48
- # end
49
- #
50
- # Produce a module to allow "include" in other classes to avoid
51
- # cluttering the namespace of the including class with the other methods defined above
52
- #
53
- module LogMethods
54
- [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m|
55
- define_method("log_#{m}") do |*params, &block|
56
- params.map! { |message| sign_message(message) }
57
- ::Protobuf::Logger.__send__(m, *params, &block)
58
- end
59
- end
60
-
61
- # When included, also extend the LogMethods module for class access.
62
- def self.included(base)
63
- base.extend(LogMethods)
64
- end
65
-
66
- # We often want to log an exception, so let's make that a core
67
- # concern of the logger.
68
- #
69
- def log_exception(ex)
70
- log_error { ex.message }
71
- log_error { ex.backtrace[0..5].join("\n") }
72
- log_debug { ex.backtrace.join("\n") }
73
- end
74
-
75
- def log_signature
76
- @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]"
77
- end
78
-
79
- def sign_message(message)
80
- "#{log_signature} #{message}"
81
- end
82
-
83
- end
84
-
85
- end
86
- end
@@ -1,136 +0,0 @@
1
- require 'protobuf/logger'
2
- require 'stringio'
3
- require 'fileutils'
4
-
5
- describe Protobuf::Logger do
6
-
7
- subject { Protobuf::Logger }
8
-
9
- before(:each) do
10
- Protobuf::Logger.reset_device!
11
- Protobuf::Logger.file = '/dev/null'
12
- Protobuf::Logger.level = ::Logger::INFO
13
- end
14
-
15
- after(:all) do
16
- ::FileUtils.rm_f('myfile.log')
17
- end
18
-
19
- describe '.instance' do
20
-
21
- it 'doesn\'t create a logger if the file was not set' do
22
- subject.file = nil
23
- expect(subject.instance).to be_nil
24
- end
25
-
26
- it 'doesn\'t create a logger if the level was not set' do
27
- subject.level = nil
28
- expect(subject.instance).to be_nil
29
- end
30
-
31
- it 'gets a new instance of the logger when file and level are set' do
32
- expect(subject.file).to_not be_nil
33
- expect(subject.level).to_not be_nil
34
- expect(subject.instance).to_not be_nil
35
- end
36
-
37
- it 'keeps the same object from multiple calls to instance' do
38
- expect(subject.instance).to equal(subject.instance)
39
- end
40
-
41
- end
42
-
43
- describe '.configure' do
44
- before(:each) { subject.reset_device! }
45
- it 'sets the file and level in one call' do
46
- expect(subject.file).to_not be
47
- expect(subject.level).to_not be
48
- expect(subject.instance).to_not be
49
- subject.configure :file => 'myfile.log', :level => ::Logger::WARN
50
- expect(subject.file).to eq('myfile.log')
51
- expect(subject.level).to eq(::Logger::WARN)
52
- expect(subject.instance.level).to eq(::Logger::WARN)
53
- end
54
-
55
- end
56
-
57
- describe '.reset_device!' do
58
-
59
- it 'resets the logger instance, file, and level' do
60
- expect(subject.instance).to be
61
- expect(subject.file).to be
62
- expect(subject.level).to be
63
- subject.reset_device!
64
- expect(subject.instance).to_not be
65
- expect(subject.file).to_not be
66
- expect(subject.level).to_not be
67
- end
68
-
69
- end
70
-
71
- context 'when logging' do
72
-
73
- it 'doesn\'t raise errors when log instance is nil' do
74
- subject.reset_device!
75
- expect(subject.instance).to be_nil
76
- expect {
77
- subject.debug 'No errors here'
78
- subject.info 'No errors here'
79
- subject.warn 'No errors here'
80
- subject.error 'No errors here'
81
- subject.fatal 'No errors here'
82
- subject.add 'No errors here'
83
- subject.log 'No errors here'
84
- }.to_not raise_error
85
- end
86
-
87
- it 'logs correctly when instance is valid' do
88
- expect(subject.instance).to_not be_nil
89
- expect(subject.instance).to receive(:info).with('Should log great')
90
- subject.info 'Should log great'
91
- end
92
-
93
- end
94
-
95
- describe Protobuf::Logger::LogMethods do
96
-
97
- context 'when included in another class' do
98
-
99
- before(:all) do
100
- class MyTestClass
101
- include Protobuf::Logger::LogMethods
102
- end
103
- end
104
-
105
- subject { MyTestClass.new }
106
-
107
- it { is_expected.to respond_to(:log_debug) }
108
- it { is_expected.to respond_to(:log_info) }
109
- it { is_expected.to respond_to(:log_warn) }
110
- it { is_expected.to respond_to(:log_error) }
111
- it { is_expected.to respond_to(:log_fatal) }
112
- it { is_expected.to respond_to(:log_add) }
113
- it { is_expected.to respond_to(:log_log) }
114
-
115
- context '#log_exception' do
116
- it 'logs the exception message as an error and backtrace as debug' do
117
- expect(subject).to receive(:log_error).twice
118
- expect(subject).to receive(:log_debug)
119
- subject.log_exception(RuntimeError.new('this is an exception'))
120
- end
121
- end
122
-
123
- specify { expect(subject.log_signature).to eq "[MyTestClass]" }
124
- describe '#sign_message' do
125
- specify { expect(subject.sign_message("this is a test")).to eq "[MyTestClass] this is a test" }
126
- specify { expect(subject.class.sign_message("this is a test")).to eq "[MyTestClass] this is a test" }
127
- end
128
-
129
- it 'passes all embedded log calls to Logger instance' do
130
- expect(Protobuf::Logger.instance).to receive(:debug).with('[MyTestClass] log this')
131
- subject.log_debug('log this')
132
- end
133
-
134
- end
135
- end
136
- end