Class: TransactionLogger::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/transaction_logger/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, lmbda) ⇒ Transaction

Returns a new instance of Transaction.

Parameters:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/transaction_logger/transaction.rb', line 16

def initialize(options, lmbda)
  @parent = options[:parent]
  @parent.log self if @parent

  @lmbda = lmbda

  @log_prefix = options[:prefix]
  @name = "undefined"
  @context = {}
  @level_threshold = options[:level_threshold] || :error
  @log_queue = []
  @start = Time.now
  @error_printed = nil
  @level_threshold_broken = false

  @logger = options[:logger]
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



9
10
11
# File 'lib/transaction_logger/transaction.rb', line 9

def context
  @context
end

#level_thresholdObject

Returns the value of attribute level_threshold.



10
11
12
# File 'lib/transaction_logger/transaction.rb', line 10

def level_threshold
  @level_threshold
end

#level_threshold_brokenObject

Returns the value of attribute level_threshold_broken.



11
12
13
# File 'lib/transaction_logger/transaction.rb', line 11

def level_threshold_broken
  @level_threshold_broken
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/transaction_logger/transaction.rb', line 8

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/transaction_logger/transaction.rb', line 6

def parent
  @parent
end

Instance Method Details

#log(message, level = :info) ⇒ Object

Pushes a message into the log queue. Logs are stored in order of time logged. Note that this method will not output a log, but just stores it in the queue to be outputted if an error is raised in a transaction.

Parameters:

  • message (#to_s)

    Any String or Object that responds to to_s that you want to be stored in the log queue.



66
67
68
69
70
71
72
73
74
75
# File 'lib/transaction_logger/transaction.rb', line 66

def log(message, level=:info)
  check_level(level)
  if message.is_a? String
    message_key = "#{@log_prefix}#{level}"
    message = { message_key => message }
    @log_queue.push message
  else
    @log_queue.push message
  end
end