semantic_logger 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ module SemanticLogger
51
51
  end
52
52
 
53
53
  str = "#{log.time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%03d" % (log.time.usec/1000)} #{log.level.to_s[0..0].upcase} [#{$$}:#{log.thread_name}] #{log.name} -- #{message}\n"
54
- str << " (#{log.duration}ms)" if log.duration
54
+ str << " (#{'%.1f' % log.duration}ms)" if log.duration
55
55
  str
56
56
  end
57
57
  end
@@ -108,13 +108,21 @@ module SemanticLogger
108
108
  @level_index <= #{index}
109
109
  end
110
110
 
111
+ # Log the duration of the supplied block
112
+ # If an exception occurs in the block the exception is logged using the
113
+ # same log level. The exception will flow through to the caller unchanged
111
114
  def benchmark_#{level}(message, payload = nil)
112
115
  raise "Mandatory block missing" unless block_given?
113
116
  if @level_index <= #{index}
114
117
  start = Time.now
115
- result = yield
116
- self.class.queue << Log.new(:#{level}, self.class.thread_name, name, message, payload, start, Time.now - start)
117
- result
118
+ begin
119
+ result = yield
120
+ self.class.queue << Log.new(:#{level}, self.class.thread_name, name, message, payload, start, Time.now - start)
121
+ result
122
+ rescue Exception => exc
123
+ self.class.queue << Log.new(:#{level}, self.class.thread_name, name, message, exc, start, Time.now - start)
124
+ raise exc
125
+ end
118
126
  else
119
127
  yield
120
128
  end
@@ -216,7 +224,7 @@ module SemanticLogger
216
224
  # #TODO Logger needs it's own "reliable" appender ;)
217
225
  # For example if an appender constantly fails
218
226
  # ( bad filename or path, invalid server )
219
- logger.debug "SemanticLogger::Logger Appender Thread Started"
227
+ logger.debug "SemanticLogger::Logger Appender thread started"
220
228
  while message=queue.pop
221
229
  if message.is_a? Log
222
230
  appenders.each {|appender| appender.log(message) }
@@ -235,10 +243,11 @@ module SemanticLogger
235
243
  end
236
244
  end
237
245
  rescue Exception => exception
238
- logger.fatal "SemanticLogger::Logger Appender Thread crashed: #{exception.class}: #{exception.message}\n#{(exception.backtrace || []).join("\n")}"
239
- exit(-2)
246
+ logger.error "SemanticLogger::Logger Appender thread restarting due to exception: #{exception.class}: #{exception.message}\n#{(exception.backtrace || []).join("\n")}"
247
+ # Start a new appender thread and let this one terminate
248
+ startup
240
249
  ensure
241
- logger.debug "SemanticLogger::Logger Appender Thread stopped"
250
+ logger.debug "SemanticLogger::Logger Appender thread stopped"
242
251
  end
243
252
  end
244
253
  end
@@ -250,7 +259,11 @@ module SemanticLogger
250
259
  logger.debug "SemanticLogger::Logger Shutdown. Stopping appender thread"
251
260
  reply_queue = Queue.new
252
261
  queue << { :command => :shutdown, :reply_queue => reply_queue }
253
- reply_queue.pop
262
+ result = reply_queue.pop
263
+ # Undefine the class variable for the queue since in test environments
264
+ # at_exit can be invoked multiple times
265
+ remove_class_variable(:@@queue)
266
+ result
254
267
  end
255
268
 
256
269
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger #:nodoc
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Reid Morrison
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-08-17 00:00:00 -04:00
17
+ date: 2012-08-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency