Module: Autoshell::Log

Included in:
Base
Defined in:
lib/autoshell/log.rb

Overview

Mixin for handling log stuff

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerLogger

Instance-specific logger

shell = Autoshell.new '~/test'
shell.logger

shell.logger = Rails.logger

Returns:

  • (Logger)

    logger instance



16
17
18
19
20
21
22
23
24
# File 'lib/autoshell/log.rb', line 16

def logger
  return @logger if defined? @logger

  @log_device = StringIO.new
  @logger = Logger.new(@log_device)
  @logger.level = LOG_LEVEL
  @logger.formatter = LOG_FORMATTER
  @logger
end

Instance Method Details

#log_output(color: false) ⇒ String

Get the complete output of the log

Returns:

  • (String)

    log contents



29
30
31
32
33
34
35
36
# File 'lib/autoshell/log.rb', line 29

def log_output(color: false)
  return unless defined? @log_device
  if color
    @log_device.string
  else
    ANSI.unansi(@log_device.string)
  end
end

#log_resetObject

Reset the log contents

Returns:

  • self



40
41
42
43
# File 'lib/autoshell/log.rb', line 40

def log_reset
  @log_device.truncate(0) if defined? @log_device
  self
end