Class: Ocak::PipelineLogger

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

Constant Summary collapse

COLORS =
{
  reset: "\e[0m",
  bold: "\e[1m",
  dim: "\e[2m",
  red: "\e[31m",
  green: "\e[32m",
  yellow: "\e[33m",
  blue: "\e[34m",
  magenta: "\e[35m",
  cyan: "\e[36m",
  white: "\e[37m"
}.freeze
AGENT_COLORS =
{
  'implementer' => :cyan,
  'reviewer' => :magenta,
  'security-reviewer' => :red,
  'auditor' => :yellow,
  'documenter' => :blue,
  'merger' => :green,
  'planner' => :white,
  'pipeline' => :cyan
}.freeze
LEVELS =
%i[quiet normal verbose].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_dir: nil, issue_number: nil, color: $stderr.tty?, log_level: :normal) ⇒ PipelineLogger

Returns a new instance of PipelineLogger.



34
35
36
37
38
39
# File 'lib/ocak/logger.rb', line 34

def initialize(log_dir: nil, issue_number: nil, color: $stderr.tty?, log_level: :normal)
  @color = color
  @log_level = LEVELS.include?(log_level) ? log_level : :normal
  @mutex = Mutex.new
  @file_logger = setup_file_logger(log_dir, issue_number) if log_dir
end

Instance Attribute Details

#log_file_pathObject (readonly)

Returns the value of attribute log_file_path.



62
63
64
# File 'lib/ocak/logger.rb', line 62

def log_file_path
  @log_file_path
end

Instance Method Details

#debug(msg, agent: nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/ocak/logger.rb', line 55

def debug(msg, agent: nil)
  @file_logger&.debug(msg)
  return unless @log_level == :verbose

  log(:debug, msg, agent: agent, color: :dim)
end

#error(msg, agent: nil) ⇒ Object



51
52
53
# File 'lib/ocak/logger.rb', line 51

def error(msg, agent: nil)
  log(:error, msg, agent: agent, color: :red)
end

#info(msg, agent: nil) ⇒ Object



41
42
43
44
45
# File 'lib/ocak/logger.rb', line 41

def info(msg, agent: nil)
  return if @log_level == :quiet

  log(:info, msg, agent: agent)
end

#warn(msg, agent: nil) ⇒ Object



47
48
49
# File 'lib/ocak/logger.rb', line 47

def warn(msg, agent: nil)
  log(:warn, msg, agent: agent, color: :yellow)
end