dldinternet-mixlib-logging 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWVlYjUwZTM1OTJhM2VlZTI2MmJhMWNiZjRhOWRhOTdhMTQwNzBhNQ==
4
+ N2MwNTdkM2RmNmI2Mzc2YjA5NDRjYjBhMzk5NGE4ODYzOGI3OTZhYw==
5
5
  data.tar.gz: !binary |-
6
- Yzc0Nzg1NGZlNWY4OTMyNjA0NTdkYmIxMjVjY2IwZjYwYzdhNWVmMQ==
6
+ ZGFiMmI5MzZjNWUxZWE3NmQwOTdjYzc5NTA3YTczMjFmMTc3NWJmOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjU5NjMzYmRmN2RhZmJhODJhNDBmMjM3OWY3N2I4NWE2YjIxYzk2ZjI1MWFl
10
- Y2NiYWM0MTViNTljYmU5YWY4ZThlZjVhY2Y3MjAxOTM3MjM2MmNkYWQ4YzIw
11
- NTgwYzdlZjNkMTA2NGRiN2I2YjUzNWQ1MzFmYmMzZDg3ZTdiMzU=
9
+ OGNiNzM2NGRhNTE5ZmQ4ZmRmM2M3Mzg2YjZlNzEwZmQ2MDE3ZmFkMDhhNzQx
10
+ NjgwMjhhYTBjMzIxMWQxZGE0ZTM3NWI2MGRkY2U5MGU3Mjk1N2Y0MzQzZTU5
11
+ MjUwMWVjYWQzZjZiZTMzMjhkMTkxYWVlNTI4ZjQ3YmM1NDI2MmQ=
12
12
  data.tar.gz: !binary |-
13
- ZTcxZjQ3Mzg0YTBlNDhlNWFhMmQxYTgzNmEwYmI1ZmNhYzRiNGExZDI1MzQx
14
- MDgyZjg0NDY5ZDU1N2QwNTI4NmQwZmFhMDUxN2E2N2IxNzA1NjFjODI1OTcz
15
- ZjFiYTdkYmRlYWFjZjlmM2Y1YzQ0NWFlYjRkMmE4OTkzYzhhNDQ=
13
+ OGQ2NjQzYTVjNTk0NWYwN2I0YWI0OTRmZDk2M2VkMWM4OWNmMjc0NzQ5ZGQ0
14
+ NzgxZjI0NmVhNjMxNzJlMTBiYmMxZDc0ZTUxNWZmZThkYTA5ZWU2ODFlY2Vm
15
+ OTE4NGQ3M2Q4MjVkNWY2NDAxYTAwMWMwZjE5Y2MxZTYyYzg1ODI=
@@ -234,12 +234,16 @@ unless defined? ::DLDInternet::Mixlib::Logging::ClassMethods
234
234
  def logEvent(evt)
235
235
  log_event evt
236
236
  end
237
+
238
+ def get_trace
239
+ @trace
240
+ end
237
241
  end
238
242
 
239
243
  class ::Logging::Layouts::Pattern
240
244
  # Arguments to sprintf keyed to directive letters
241
245
  verbose, $VERBOSE = $VERBOSE, nil
242
- # noinspection RubyStringKeysInHashInspection
246
+ # noinspection RubyStringKeysInHashInspection,RubyExpressionInStringInspection
243
247
  DIRECTIVE_TABLE = {
244
248
  'C' => 'event.file != "" ? "(\e[38;5;25m#{event.file}::#{event.line}\e[0m)" : ""',
245
249
  'c' => 'event.logger'.freeze,
@@ -325,11 +329,64 @@ unless defined? ::DLDInternet::Mixlib::Logging::ClassMethods
325
329
  end
326
330
  end
327
331
 
332
+ module ::Logging
333
+
334
+ # This class defines a logging event.
335
+ #
336
+ remove_const :LogEvent if defined? :LogEvent
337
+ LogEvent = Struct.new( :logger, :level, :data, :time, :file, :line, :method ) {
338
+ # :stopdoc:
339
+ class << self
340
+ attr_accessor :caller_index
341
+ end
342
+
343
+ # Regular expression used to parse out caller information
344
+ #
345
+ # * $1 == filename
346
+ # * $2 == line number
347
+ # * $3 == method name (might be nil)
348
+ # CALLER_RGXP = %r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
349
+ # CALLER_INDEX = ((defined? JRUBY_VERSION and JRUBY_VERSION > '1.6') or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2
350
+ # :startdoc:
351
+
352
+ # call-seq:
353
+ # LogEvent.new( logger, level, [data], trace )
354
+ #
355
+ # Creates a new log event with the given _logger_ name, numeric _level_,
356
+ # array of _data_ from the user to be logged, and boolean _trace_ flag.
357
+ # If the _trace_ flag is set to +true+ then Kernel::caller will be
358
+ # invoked to get the execution trace of the logging method.
359
+ #
360
+ def initialize( logger, level, data, trace )
361
+ f = l = m = ''
362
+
363
+ if trace
364
+ stack = Kernel.caller[::Logging::LogEvent.caller_index]
365
+ return if stack.nil?
366
+
367
+ match = CALLER_RGXP.match(stack)
368
+ f = match[1]
369
+ l = Integer(match[2])
370
+ m = match[3] unless match[3].nil?
371
+ end
372
+
373
+ super(logger, level, data, Time.now, f, l, m)
374
+ end
375
+ }
376
+ ::Logging::LogEvent.caller_index = CALLER_INDEX
377
+ end # module Logging
378
+
328
379
  # -----------------------------------------------------------------------------
329
380
  def logStep(msg,cat='Step')
330
381
  logger = getLogger(@logger_args, 'logStep')
331
382
  if logger
383
+ if logger.get_trace
384
+ ::Logging::LogEvent.caller_index += 1
385
+ end
332
386
  logger.step "#{cat} #{@step+=1}: #{msg} ..."
387
+ if logger.get_trace
388
+ ::Logging::LogEvent.caller_index -= 1
389
+ end
333
390
  end
334
391
  end
335
392
 
@@ -2,7 +2,7 @@ module Dldinternet
2
2
  module Mixlib
3
3
  module Logging
4
4
  # dldinternet-mixlib-logging version
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dldinternet-mixlib-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging