require 'logger' require 'json' require 'time' require File.expand_path('../common', __FILE__) require File.expand_path('../common_json', __FILE__) module Ruby module JSONFormatter class Base < ::Logger::Formatter include Logifyer::Common include Logifyer::Common::JSON ANSI_ESCAPE_REGEX = /\e\[(?:\d+;\d+;?\d*|[\d\w])m/.freeze def initialize(app = nil, ext = {}) @app = app @ext = ext.is_a?(Hash) ? ext : {ext_info: ext.inspect} @config = { level: :log_level, app: :application, timestamp: :timestamp } yield @config if block_given? end def call(severity, time, progname, message) cleaned_message = strip_ansi_escape_codes(message) @event = build_event(cleaned_message, severity, time) end private def strip_ansi_escape_codes(text) text.gsub(ANSI_ESCAPE_REGEX, '') end end end end