lib/carioca/services/output.rb in carioca-2.0.5 vs lib/carioca/services/output.rb in carioca-2.0.6

- old
+ new

@@ -39,11 +39,12 @@ sending: { value: "\u{1F4E4}", alt: '[>]', text: '(SENDING)' }, receive: { value: "\u{1F4E5}", alt: '[<]', text: '(RECEIVE)' }, ok: { value: "\u{1F44D}", alt: '[+]', text: '(OK)' }, success: { value: "\u{1F4AA}", alt: '[+]', text: '(SUCCESS)' }, debug: { value: "\u{1F41B}", alt: '[D]', text: '(DEBUG)' }, - flat: { value: '', alt: '' } + flat: { value: '', alt: '' }, + skip: { value: 'U{23E9}', alt: '[I]', text: '(SKIPPED)'} }.freeze LEVELS = %i[debug info warn error fatal unknown].freeze ALIAS = { flat: :info, item: :info, @@ -53,11 +54,12 @@ scheduling: :info, arrow: :info, sending: :info, calling: :info, receive: :info, - success: :info + success: :info, + skipped: :info }.freeze end class Provider @@ -67,19 +69,19 @@ @@alias = ALIAS.dup @@colors = COLORS.dup @@emoji = EMOJI.dup - MODE = %i[mono dual].freeze + MODE = %i[mono dual log].freeze LEVELS.each do |method| - define_method(method) do |message, session = '', source = 'Carioca->Output'| + define_method(method) do |message, session = nil, source = 'Carioca->Output'| display(level: method, message: message, session: session, source: source) end end @@alias.each_key do |method| - define_method(method) do |message, session = '', source = 'Carioca->Output'| + define_method(method) do |message, session = nil, source = 'Carioca->Output'| display(level: method, message: message, session: session, source: source) end end def map_color(color:, analias:) @@ -98,11 +100,11 @@ def add_alias(newalias:, level:) raise 'Alias must be a Symbol' unless newalias.instance_of?(Symbol) raise "Bad Level : #{level}" unless LEVELS.include? level - self.class.define_method(newalias) do |message, session = ''| + self.class.define_method(newalias) do |message, session = nil| display({ level: newalias, message: message, session: session }) end end # constructor @@ -158,11 +160,11 @@ # @param [Hash] params # @option params [Symbol] :level, a valid level in LEVELS or ALIAS # @option params [String] :message text # @option params [String] :session an id/timestamp of session def display(level:, message:, session:, source:) - message << "(#{session})" if session + message << " (#{session})" if session save = message.dup target_level = @@alias.keys.include?(level) ? @@alias[level] : level if @active_levels.include? target_level if @color pastel = ::Pastel.new @@ -176,10 +178,10 @@ if @mode == :dual save = "#{@@emoji[level][:text]} #{save}" if !LEVELS.include?(level) && (@@emoji[level].include? :text) block = proc { save } @logger.send target_level, source, &block end - puts message + puts message if @mode == :mono or @mode == :dual end end end end end