Class: TwentyFortyEight::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/TwentyFortyEight/logger.rb

Overview

Logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



7
8
9
# File 'lib/TwentyFortyEight/logger.rb', line 7

def initialize
  @entries = []
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



5
6
7
# File 'lib/TwentyFortyEight/logger.rb', line 5

def entries
  @entries
end

Instance Method Details

#<<(info_hsh) ⇒ Object



11
12
13
# File 'lib/TwentyFortyEight/logger.rb', line 11

def <<(info_hsh)
  entries << { time: (Time.now.to_f * 1000).to_i, info: info_hsh }
end

#write!(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/TwentyFortyEight/logger.rb', line 15

def write!(options = {})
  name = (options[:name] || "2048-#{Time.now.to_i}") + '.log.json'
  path = File.expand_path(options[:path]) if options[:path]
  path = File.join(Dir.pwd, name) unless options[:dir]
  path = (File.join Dir.pwd, options[:dir], name) if options[:dir]

  File.open(path, 'w') { |f| f.write @entries.to_json }
end