Class: ProcessBot::Logger
- Inherits:
-
Object
- Object
- ProcessBot::Logger
- Defined in:
- lib/process_bot/logger.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #fp_log ⇒ Object
-
#initialize(options:) ⇒ Logger
constructor
A new instance of Logger.
- #log(output, type: :stdout) ⇒ Object
- #log_file_path ⇒ Object
- #log_to_file? ⇒ Boolean
- #logs(output, **args) ⇒ Object
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 = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/process_bot/logger.rb', line 2 def @options end |
Instance Method Details
#fp_log ⇒ Object
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 && [: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_path ⇒ Object
27 28 29 |
# File 'lib/process_bot/logger.rb', line 27 def log_file_path .fetch(:log_file_path) end |
#log_to_file? ⇒ Boolean
31 32 33 |
# File 'lib/process_bot/logger.rb', line 31 def log_to_file? .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 |