Class: Bitlogger::PrettyFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/bitlogger/pretty_formatter.rb

Instance Method Summary collapse

Constructor Details

#initializePrettyFormatter

Returns a new instance of PrettyFormatter.



4
5
6
# File 'lib/bitlogger/pretty_formatter.rb', line 4

def initialize
  @offset = DateTime.now.offset
end

Instance Method Details

#format_hash(hash) ⇒ String

Parameters:

  • msg (Hash)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bitlogger/pretty_formatter.rb', line 10

def format_hash(hash)
  str = ""
  hash.each do |k, v|
    str += "[#{k}: #{v}] " unless k == :level or k == :timestamp
  end

  dt = DateTime.strptime(hash[:timestamp].to_s, '%s')
  dt = dt.new_offset(@offset)

  "[#{dt}] [#{hash[:level]}] #{str}"
end