Class: Legion::TTY::BootLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/tty/boot_logger.rb

Constant Summary collapse

LOG_DIR =
File.expand_path('~/.legionio/logs')
LOG_FILE =
File.join(LOG_DIR, 'tty-boot.log')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: LOG_FILE) ⇒ BootLogger

Returns a new instance of BootLogger.



11
12
13
14
15
16
# File 'lib/legion/tty/boot_logger.rb', line 11

def initialize(path: LOG_FILE)
  @path = path
  FileUtils.mkdir_p(File.dirname(@path))
  File.write(@path, '')
  log('boot', 'legion-tty boot logger started')
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



31
32
33
# File 'lib/legion/tty/boot_logger.rb', line 31

def path
  @path
end

Instance Method Details

#log(source, message) ⇒ Object



18
19
20
21
22
# File 'lib/legion/tty/boot_logger.rb', line 18

def log(source, message)
  ts = Time.now.strftime('%H:%M:%S.%L')
  line = "[#{ts}] [#{source}] #{message}\n"
  File.open(@path, 'a') { |f| f.write(line) }
end

#log_hash(source, label, hash) ⇒ Object



24
25
26
27
28
29
# File 'lib/legion/tty/boot_logger.rb', line 24

def log_hash(source, label, hash)
  log(source, "#{label}:")
  hash.each do |k, v|
    log(source, "  #{k}: #{v.inspect}")
  end
end