Class: ProcessBot::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:) ⇒ Logger

Returns a new instance of Logger.



4
5
6
# File 'lib/process_bot/logger.rb', line 4

def initialize(options:)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/process_bot/logger.rb', line 2

def options
  @options
end

Instance Method Details

#fp_logObject



35
36
37
# File 'lib/process_bot/logger.rb', line 35

def fp_log
  @fp_log ||= File.open(log_file_path, "a") if log_to_file?
end

#log(output, type: :stdout) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/process_bot/logger.rb', line 8

def log(output, type: :stdout)
  if type == :stdout || (type == :debug && options[:debug])
    $stdout.print output
  elsif type == :stderr
    $stderr.print output
  else
    raise "Unknown type: #{type}"
  end

  return unless log_to_file?

  fp_log.write(output)
  fp_log.flush
end

#log_file_pathObject



27
28
29
# File 'lib/process_bot/logger.rb', line 27

def log_file_path
  options.fetch(:log_file_path)
end

#log_to_file?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/process_bot/logger.rb', line 31

def log_to_file?
  options.present?(:log_file_path)
end

#logs(output, **args) ⇒ Object



23
24
25
# File 'lib/process_bot/logger.rb', line 23

def logs(output, **args)
  log("#{output}\n", **args)
end