Class: LogPretty::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/log-pretty/logger.rb

Overview

Initialize a custom logger if setting the device or formatter

Instance Method Summary collapse

Constructor Details

#initialize(log_device = nil, formatter = nil, **_opts) ⇒ Logger



9
10
11
12
# File 'lib/log-pretty/logger.rb', line 9

def initialize(log_device = nil, formatter = nil, **_opts)
  @log_device = log_device || $stdout
  @formatter = formatter || default_formatter
end

Instance Method Details

#logp(input) ⇒ Object

Will print to custom loggin device, if other than STDOUT, STDOUT by default, and returns output



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/log-pretty/logger.rb', line 16

def logp(input, **)
  output = AnsiPrinter.new(input:, **).output

  # print to logger
  logger.info(output)

  # print to $stdout unless it already is.
  $stdout.puts(output) unless logger.instance_variable_get(:@logdev).dev == $stdout

  # return value
  output
end