Module: PierConsoleDetective::Utils

Defined in:
lib/pier_console_detective/utils.rb

Constant Summary collapse

LOGGER_PROC =
->(message, data) do
  PierConsoleDetective::Utils.logger.info(message, {
    data: data,
    tag: PierConsoleDetective::Utils.get_tag,
  })
end

Class Method Summary collapse

Class Method Details

.get_tagObject



16
17
18
19
# File 'lib/pier_console_detective/utils.rb', line 16

def self.get_tag
  return @tag if PierConsoleDetective.tag_memoization && @tag
  @tag = PierConsoleDetective.log_tag.call
end

.log_command(command, immediately: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/pier_console_detective/utils.rb', line 21

def self.log_command(command, immediately: false)
  return Thread.new { 
    PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", {
      command: command.inspect
    }) 
  } unless immediately
  PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", {
    command: command.inspect
  })
end

.log_command_output(command, output, immediately: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pier_console_detective/utils.rb', line 32

def self.log_command_output(command, output, immediately: false)
  return Thread.new {
    PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", {
      command: command.inspect,
      output: output.inspect,
    })
  } unless immediately
  PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", {
    command: command.inspect,
    output: output.inspect,
  })
end

.loggerObject



12
13
14
# File 'lib/pier_console_detective/utils.rb', line 12

def self.logger
  @logger ||= PierConsoleDetective.logger
end