Module: Whoop::Main
- Defined in:
- lib/whoop.rb
Constant Summary collapse
- COLORS =
%i[black red green yellow blue magenta cyan white light_black light_red light_green light_yellow light_blue light_magenta light_cyan light_white default].freeze
- FORMATS =
%i[plain pretty json sql].freeze
- PATTERN =
"-"
- COUNT =
80
- INDENT =
"┆"
- TOP_LINE_CHAR =
"┏"
- BOTTOM_LINE_CHAR =
"┗"
Instance Method Summary collapse
-
#whoop(label = nil, pattern: PATTERN, count: COUNT, color: :default, format: :pretty, caller_depth: 0, explain: false, tags: [], context: nil) ⇒ Object
Log the message to the logger.
Instance Method Details
#whoop(label = nil, pattern: PATTERN, count: COUNT, color: :default, format: :pretty, caller_depth: 0, explain: false, tags: [], context: nil) ⇒ Object
Log the message to the logger
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/whoop.rb', line 50 def whoop( label = nil, pattern: PATTERN, count: COUNT, color: :default, format: :pretty, caller_depth: 0, explain: false, tags: [], context: nil ) = block_given? ? yield : label if Whoop.logger.is_a?(SemanticLogger::Logger) context ||= {} if .length > 0 Whoop.logger.tagged(*) do Whoop.logger.send(Whoop.level.to_sym, , **context) end else Whoop.logger.send(Whoop.level.to_sym, , **context) end return end if .length > 0 context ||= {} context[:tags] = end logger_method = detect_logger_method color_method = detect_color_method(color) formatter_method = detect_formatter_method(format, colorize: color.present?, explain: explain) caller_path = clean_caller_path(caller[caller_depth]) line = pattern * count caller_path_line = [color_method.call(INDENT), "source:".colorize(:light_black).underline, caller_path].join(" ") = [color_method.call(INDENT), "timestamp:".colorize(:light_black).underline, Time.now].join(" ") context_lines = if context.is_a?(Hash) && context.keys.length > 0 context.map do |k, v| [color_method.call(INDENT), "#{k}:".colorize(:light_black).underline, v].join(" ") end else [] end top_line = if label.present? && label.is_a?(String) wrapped_line(label.to_s, pattern: pattern, count: count) else pattern * count end logger_method.call color_method.call top_line logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{top_line}" logger_method.call logger_method.call caller_path_line context_lines.each { |l| logger_method.call l } logger_method.call "" logger_method.call formatter_method.call() logger_method.call "" (format, color_method, logger_method) logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n" end |