Class: Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/rest-ftp-daemon/logger.rb

Instance Method Summary collapse

Instance Method Details

#build_prefix(context = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/rest-ftp-daemon/logger.rb', line 34

def build_prefix context = {}
  LOG_FORMAT_MESSAGE % [
    context[:wid].to_s,
    context[:jid].to_s,
    context[:id].to_s,
    context[:level].to_i + 1,
  ]
end

#info_with_id(message, context = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rest-ftp-daemon/logger.rb', line 5

def info_with_id message, context = {}
  # Ensure context is a hash of options and init
  context = {} unless context.is_a? Hash
  context[:level] ||= Logger::DEBUG

  # Build prefixes depending on this context
  prefix1 = build_prefix(context)
  prefix2 = build_prefix + "   | "

  lines = context[:lines]

  if lines.is_a? Hash
    output = build_from_hash prefix2, lines

  elsif lines.is_a? Array
    output = build_from_array prefix2, lines

  else
    output = []

  end

  # Prepend plain message to output
  output.unshift prefix1 + message.force_encoding(Encoding::UTF_8)

  # Send all this to logger
  add context[:level], output
end