Class: Roast::LogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Roast::LogFormatter
- Defined in:
- lib/roast/log_formatter.rb
Constant Summary collapse
- TTY_FORMAT =
: String
"• %.1s, %s\n"- NON_TTY_FORMAT =
: String
"%.1s, [%s] %5s -- %s\n"- DATETIME_FORMAT =
: String
"%Y-%m-%dT%H:%M:%S.%6N"
Instance Method Summary collapse
- #call(severity, time, _progname, msg) ⇒ Object
-
#initialize(tty:) ⇒ LogFormatter
constructor
: (tty: bool) -> void.
Constructor Details
#initialize(tty:) ⇒ LogFormatter
: (tty: bool) -> void
11 12 13 14 15 |
# File 'lib/roast/log_formatter.rb', line 11 def initialize(tty:) super() @tty = tty @rainbow = Rainbow.new.tap { |r| r.enabled = tty } end |
Instance Method Details
#call(severity, time, _progname, msg) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/roast/log_formatter.rb', line 17 def call(severity, time, _progname, msg) type = msg.is_a?(Roast::Log::Message) ? msg.type : nil line = if @tty format(TTY_FORMAT, severity, msg2str(msg)) else format(NON_TTY_FORMAT, severity, time.strftime(DATETIME_FORMAT), severity, msg2str(msg)) end colourize(severity, type, line) end |