bin/betterlog in betterlog-0.10.0 vs bin/betterlog in betterlog-0.11.0

- old
+ new

@@ -25,16 +25,16 @@ -c to enable colors during pretty printing -f to follow the log files -h to display this help -p FORMAT to pretty print the log file if possible -e EMITTER only output events from these emitters - -s MATCH only display events matching this search string + -s MATCH only display events matching this search string (can be repeated) -S SEVERITY only output events with severity, e. g. -S '>=warn' -n NUMBER rewind this many lines backwards before tailing log file -F SHORTCUT to open the config files with SHORTCUT - FORMAT values are: #{Array(cc.log.formats?&.attribute_names) * ?,} + FORMAT values are: #{(Array(cc.log.formats?&.attribute_names) + %w[j json]) * ?,} SEVERITY values are: #{Log::Severity.all * ?|} Config file SHORTCUTs are: #{Array(cc.log.config_files?&.attribute_names) * ?,} @@ -91,26 +91,32 @@ def emitters Array(@opts[?e]) end def search_matched?(event) - case @opts[?s] - when /:\?\z/ - event[$`].present? - when /:([^:]+)\z/ - event[$`].full?(:include?, $1) - when String - event.to_json.include?(@opts[?s]) - else - return true + return true unless @opts[?s] + @opts[?s].all? do |param| + case param + when /:\?\z/ + event[$`].present? + when /:([^:]+)\z/ + event[$`].full?(:include?, $1) + when String + event.to_json.include?(@opts[?s]) + else + return true + end end end def output_log_event(prefix, event) return unless @severities.include?(event.severity) return if emitters.full? && !emitters.include?(event.emitter) search_matched?(event) or return - if format = @opts[?p] + format = @opts[?p]&.to_sym + if format == :json || format == :j + puts event.format(pretty: false, color: @opts[?c]) + elsif format puts event.format(pretty: :format, color: @opts[?c], format: format) else puts "#{prefix}#{event}" end end