File: logging.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module TestProf
  # Helper for output printing
  module Logging
    COLORS = {
      info: "\e[34m", # blue
      warn: "\e[33m", # yellow
      error: "\e[31m" # red
    }.freeze

    def log(level, msg)
      TestProf.config.output.puts(build_log_msg(level, msg))
    end

    def build_log_msg(level, msg)
      colorize(level, "[TEST PROF #{level.to_s.upcase}] #{msg}")
    end

    def colorize(level, msg)
      return msg unless TestProf.config.color?

      "#{COLORS[level]}#{msg}\e[0m"
    end
  end
end