lwes-logger 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 1.0.1 / 2010-10-11
2
+
3
+ * Enhancements:
4
+
5
+ * Added support for blocks for meta event data and additional logging data.
6
+
7
+
1
8
  === 1.0.0 / 2010-10-05
2
9
 
3
10
  * 1 major enhancement
data/lib/lwes_logger.rb CHANGED
@@ -10,7 +10,7 @@ require 'uuidtools'
10
10
 
11
11
  class LwesLogger < Logger
12
12
 
13
- VERSION = '1.0.0'
13
+ VERSION = '1.0.1'
14
14
 
15
15
  HOSTNAME = Socket.gethostname
16
16
  FORMAT = "%s [%s#%d] %5s -- %s: %s\n"
@@ -74,7 +74,7 @@ class LwesLogger < Logger
74
74
 
75
75
  ##
76
76
  # Dump given message to the log device without any formatting.
77
- # Creates an LwesLogger::Any event.
77
+ # Creates an LwesLogger::Any event.@options[:request].
78
78
 
79
79
  def << msg
80
80
  emit_log nil, msg
@@ -132,8 +132,12 @@ class LwesLogger < Logger
132
132
  :timestamp => Time.now.strftime(@datetime_format),
133
133
  :event_id => event_id
134
134
 
135
- data = data.dup
136
- data.each{|k, v| event_hash[k] = v.to_s}
135
+ event_hash.merge! data
136
+
137
+ event_hash.each do |key, val|
138
+ val = val.call if Proc === val
139
+ event_hash[key] = val.to_s
140
+ end
137
141
 
138
142
  event_hash
139
143
  end
@@ -147,6 +151,15 @@ class LwesLogger < Logger
147
151
  end
148
152
 
149
153
 
154
+ ##
155
+ # Access the meta-event hash to set default values. If given a key and block,
156
+ # the block will be run on every log output.
157
+
158
+ def meta_event_attr key, value=nil, &block
159
+ @meta_event[key] = value || (block if block_given?)
160
+ end
161
+
162
+
150
163
  private
151
164
 
152
165
 
@@ -225,6 +225,19 @@ class TestLwesLogger < Test::Unit::TestCase
225
225
  end
226
226
 
227
227
 
228
+ def test_build_log_event_proc_data
229
+ @logger.meta_event_attr :test1 do
230
+ "value1"
231
+ end
232
+
233
+ block = lambda{:value2}
234
+ hash = @logger.build_log_event nil, nil, nil, :test2 => block
235
+
236
+ assert_equal "value1", hash[:test1]
237
+ assert_equal "value2", hash[:test2]
238
+ end
239
+
240
+
228
241
  def test_emit_log
229
242
  event_hash = @logger.build_log_event Logger::DEBUG, "log msg"
230
243
 
@@ -259,6 +272,23 @@ class TestLwesLogger < Test::Unit::TestCase
259
272
  end
260
273
 
261
274
 
275
+ def test_meta_event_attr
276
+ @logger.meta_event_attr :test1, "value1"
277
+
278
+ @logger.meta_event_attr :test2 do
279
+ "value2"
280
+ end
281
+
282
+ @logger.meta_event_attr :test3, "value3" do
283
+ "not this value!"
284
+ end
285
+
286
+ assert_equal "value1", @logger.meta_event[:test1]
287
+ assert_equal "value2", @logger.meta_event[:test2].call
288
+ assert_equal "value3", @logger.meta_event[:test3]
289
+ end
290
+
291
+
262
292
  def test_call_format
263
293
  time = Time.now
264
294
  timestamp = time.strftime("%b %d %H:%M:%S")
@@ -289,13 +319,18 @@ class TestLwesLogger < Test::Unit::TestCase
289
319
 
290
320
  def add_emit_hooks emitter
291
321
  emitter.instance_eval do
322
+ undef emit
292
323
  def emit *args
293
324
  @emitted ||= []
294
325
  @emitted << args
295
326
  end
327
+
328
+ undef emitted if defined?(emitted)
296
329
  def emitted
297
330
  @emitted
298
331
  end
332
+
333
+ undef reset_emitted if defined?(reset_emitted)
299
334
  def reset_emitted
300
335
  @emitted = []
301
336
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lwes-logger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremie Castagna
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-08 00:00:00 -07:00
18
+ date: 2010-10-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency