Class: Legion::TTY::BootLogger
- Inherits:
-
Object
- Object
- Legion::TTY::BootLogger
- Defined in:
- lib/legion/tty/boot_logger.rb
Constant Summary collapse
- LOG_DIR =
File.('~/.legionio/logs')
- LOG_FILE =
File.join(LOG_DIR, 'tty-boot.log')
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path: LOG_FILE) ⇒ BootLogger
constructor
A new instance of BootLogger.
- #log(source, message) ⇒ Object
- #log_hash(source, label, hash) ⇒ Object
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
#path ⇒ Object (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, ) ts = Time.now.strftime('%H:%M:%S.%L') line = "[#{ts}] [#{source}] #{}\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 |