Skip to content

Commit

Permalink
Allow logger to accept arbitrary options and log them after subject.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 7, 2020
1 parent 1c4f539 commit e117d69
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/console/terminal/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require_relative 'text'
require_relative 'xterm'

require 'json'

module Console
module Terminal
# This, and all related methods, is considered private.
Expand Down Expand Up @@ -94,7 +96,7 @@ def register_defaults(terminal)

UNKNOWN = 'unknown'

def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block)
def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, **options, &block)
prefix = build_prefix(name || severity.to_s)
indent = " " * prefix.size

Expand All @@ -104,6 +106,10 @@ def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block)
format_subject(severity, prefix, subject, buffer)
end

if options&.any?
format_options(options, buffer)
end

arguments.each do |argument|
format_argument(argument, buffer)
end
Expand All @@ -121,6 +127,10 @@ def call(subject = nil, *arguments, name: nil, severity: UNKNOWN, &block)

protected

def format_options(options, output)
format_value(options.to_json, output)
end

def format_argument(argument, output)
case argument
when Exception
Expand Down

0 comments on commit e117d69

Please sign in to comment.