Class: TwentyFortyEight::Logger
- Inherits:
-
Object
- Object
- TwentyFortyEight::Logger
- Defined in:
- lib/TwentyFortyEight/logger.rb
Overview
Logger
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #<<(info_hsh) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #write!(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
7 8 9 |
# File 'lib/TwentyFortyEight/logger.rb', line 7 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (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!( = {}) name = ([:name] || "2048-#{Time.now.to_i}") + '.log.json' path = File.([:path]) if [:path] path = File.join(Dir.pwd, name) unless [:dir] path = (File.join Dir.pwd, [:dir], name) if [:dir] File.open(path, 'w') { |f| f.write @entries.to_json } end |