tq 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2607111dfe096e9497fe2998bdfae1f26adc4ab
4
- data.tar.gz: 0588748479920a858bcfd5931a032265a75ef79c
3
+ metadata.gz: f1189c610b90b4d6e1af73a3e075981588797bff
4
+ data.tar.gz: dd0f3598d6261f985e8830d0bb73d848f29fce0c
5
5
  SHA512:
6
- metadata.gz: 057f43875d39cda15a42423f8e35d4ac0ca852ac63ca0b40c30005d180ac5ed5c7b67f3907ed7c7f1d1428461e6885d28217e8a86cd1f33f59bd66f3af2ffc83
7
- data.tar.gz: e9a86c79db545598a8ecc8494f49f9c11376bced85e00a5f6e4ed452345d2cfcd7ce0e3b42beb68a7031076f1b42420aed06e207956c41143356886cd7cc6735
6
+ metadata.gz: 0684ba5f822f4ee215c131d7c56d0f9f939309b8faa85c8cebcf140da75b9e0212586dac3e093acffb3b224af28c2d855aa23c3dbf4c3171e9678bb6b8c01bab
7
+ data.tar.gz: a178c5c079388733ad77f4e075bd1ecc14346a48aad514275a48d5a08161dbbe30ecf77dffef32c0d7ca8a5cc3f8ddf57d26752e4f268362cca0e691f35c5d6d
data/lib/tq/logger.rb CHANGED
@@ -36,10 +36,13 @@ module TQ
36
36
  end
37
37
 
38
38
  def add(severity, message=nil, progname=nil, context=nil, &block)
39
- t = Time.now
40
- @log.add(severity, message, progname, &block)
39
+ t = Time.now
40
+ severity, message, data, context =
41
+ normalize_params(severity, message, progname, context, &block)
42
+
43
+ @log.add(severity, message, data[:progname])
41
44
  @queue.push!(
42
- queue_message(t, severity, message, progname, context, &block),
45
+ queue_message(t, severity, message, data, context),
43
46
  ::Logger::SEV_LABEL[severity].to_s.downcase
44
47
  ) if (severity >= level)
45
48
  end
@@ -64,7 +67,7 @@ module TQ
64
67
 
65
68
  # damn, the ruby logger interface is weird... this logic is copied almost verbatim
66
69
  # from ::Logger.add
67
- def queue_message(t, severity, message, progname, context, &block)
70
+ def normalize_params(severity, message, progname, context, &block)
68
71
  severity ||= ::Logger::UNKNOWN
69
72
  progname ||= self.progname
70
73
  if message.nil?
@@ -75,16 +78,27 @@ module TQ
75
78
  progname = self.progname
76
79
  end
77
80
  end
81
+
82
+ # for case where progname is passed as hash
83
+ data = {}
84
+ if progname.respond_to?(:has_key?) && progname.respond_to?(:merge)
85
+ data = {progname: self.progname}.merge(progname)
86
+ else
87
+ data = {progname: progname}
88
+ end
89
+
90
+ return [severity, message, data, context]
91
+ end
78
92
 
79
- return {
93
+ def queue_message(t, severity, message, data={}, context={})
94
+ return data.merge({
80
95
  time: t.iso8601,
81
96
  timestamp: t.to_i,
82
97
  level: severity,
83
98
  label: ::Logger::SEV_LABEL[severity],
84
99
  message: message,
85
- progname: progname,
86
100
  context: context
87
- }
101
+ })
88
102
  end
89
103
 
90
104
  end
data/lib/tq/queue.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+ require 'base64'
1
3
 
2
4
  module TQ
3
5
 
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module TQ
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
data/test/test_logger.rb CHANGED
@@ -46,14 +46,21 @@ class LoggerTests < Minitest::Spec
46
46
  exps.each_with_index do |exp,i|
47
47
  act = acts[i]
48
48
  next if act.nil?
49
- [:level, :message, :progname].each do |elem|
49
+ [:level, :message].each do |elem|
50
50
  unless (a = exp[elem]) == (b = act[elem.to_s])
51
51
  errs.push( "[#{i}] Expected #{elem} to be #{a}, was #{b}" )
52
52
  end
53
53
  end
54
+
55
+ a = (Hash === exp[:progname] ? exp[:progname][:progname] : exp[:progname])
56
+ unless a == (b = act['progname'])
57
+ errs.push( "[#{i}] Expected #{elem} to be #{a}, was #{b}" )
58
+ end
59
+
54
60
  unless (a = ::Logger::SEV_LABEL[exp[:level]]) == (b = act['label'])
55
61
  errs.push( "[#{i}] Expected label to be #{a}, was #{b}" )
56
62
  end
63
+
57
64
  end
58
65
  assert errs.length == 0, errs.join("\n")
59
66
  end
@@ -179,6 +186,49 @@ class LoggerTests < Minitest::Spec
179
186
 
180
187
  end
181
188
 
189
+ it 'log methods should accept hash of values as first parameter' do
190
+ subject = TQ::Logger.new(@queue, test_logger )
191
+
192
+ expected_messages = [
193
+ { method: :debug,
194
+ level: ::Logger::DEBUG,
195
+ progname: {
196
+ progname: 'prog1', id: '1234'
197
+ },
198
+ message: 'debug message',
199
+ context: { key: 1 }
200
+ },
201
+ { method: :info,
202
+ level: ::Logger::INFO,
203
+ progname: {
204
+ id: '2345', progname: 'prog2'
205
+ },
206
+ message: 'info message',
207
+ context: { key: 2 }
208
+ },
209
+ { method: :warn,
210
+ message: 'warn message',
211
+ level: ::Logger::WARN,
212
+ progname: {
213
+ id: '3456', progname: 'prog3'
214
+ }
215
+ },
216
+ { method: :error,
217
+ message: 'error message',
218
+ level: ::Logger::ERROR,
219
+ progname: {
220
+ progname: 'prog4', id: '4567'
221
+ },
222
+ context: { key: 4 }
223
+ }
224
+ ]
225
+
226
+ send_messages_to!(subject, expected_messages)
227
+
228
+ verify_logged_messages_to_level! expected_messages, test_logger.level
229
+
230
+ end
231
+
182
232
  end
183
233
 
184
234
  setup_test_logger!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Gjertsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client