diff --git a/app/controllers/hot_controller.rb b/app/controllers/hot_controller.rb index 725a560..931c758 100644 --- a/app/controllers/hot_controller.rb +++ b/app/controllers/hot_controller.rb @@ -1,6 +1,6 @@ class HotController < ApplicationController def index - session[:toto1] = session[:toto1].nil? ? 'blabla' : nil + session[:toto1] = session[:toto1].nil? ? "id##{Random.rand(10)}" : nil logger.info('callee') logger.info(__callee__) logger.info(__method__) diff --git a/lib/monkey_patches/action_dispatch/debug_exceptions.rb b/lib/monkey_patches/action_dispatch/debug_exceptions.rb deleted file mode 100644 index 3657a85..0000000 --- a/lib/monkey_patches/action_dispatch/debug_exceptions.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions' - -module ActionDispatch - # patched class to prevent deprecated message - class DebugExceptions - private - - def log_error(_request, wrapper) - Rails.application.deprecators.silence do - ActionController::Base.logger.fatal(wrapper.exception) - end - end - end -end diff --git a/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb b/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb new file mode 100644 index 0000000..8ac8504 --- /dev/null +++ b/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb @@ -0,0 +1,39 @@ +require 'action_dispatch/middleware/exception_wrapper' +require 'action_dispatch/routing/inspector' + +require 'action_view' + +module ActionDispatch + # patched class to prevent deprecated message + class DebugExceptions + private + + def render_exception(request, exception, wrapper) + ## PVINCENT's ADDITION for TagWrapError + log_error(request, wrapper) + + if exception.is_a?(Semantic::TagWrapError) + backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner') + wrapper = ExceptionWrapper.new(backtrace_cleaner, exception.error) + end + + # log_error(request, wrapper) + + ## END OF ADDITION + + raise exception unless request.get_header('action_dispatch.show_detailed_exceptions') + + begin + content_type = request.formats.first + rescue ActionDispatch::Http::MimeNegotiation::InvalidType + content_type = Mime[:text] + end + + if api_request?(content_type) + render_for_api_request(content_type, wrapper) + else + render_for_browser_request(request, wrapper) + end + end + end +end diff --git a/lib/semantic/ansi_formatter.rb b/lib/semantic/ansi_formatter.rb index b82757c..6855577 100644 --- a/lib/semantic/ansi_formatter.rb +++ b/lib/semantic/ansi_formatter.rb @@ -164,7 +164,15 @@ module Semantic def exception return unless log.exception - exc = log.exception + if log.exception.is_a?(Semantic::TagWrapError) + exc_wrapper = log.exception + # puts "TAG_WRAP detected #{exc_wrapper.tag}" + exc = exc_wrapper.error + log.tags = Array.wrap(exc_wrapper.tag) + else + exc = log.exception + end + clazz = colorize("#{exc.class}\n", color_map[:fatal]) message = colorize(exc.message.chomp(''), color_map[:error]) backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace)) diff --git a/lib/semantic/tag_wrap_error.rb b/lib/semantic/tag_wrap_error.rb new file mode 100644 index 0000000..5c2abb6 --- /dev/null +++ b/lib/semantic/tag_wrap_error.rb @@ -0,0 +1,14 @@ +module Semantic + # custom Error for dispatching a remanent tag + class TagWrapError < StandardError + attr_reader :error, :tag + + def initialize(tag, error) + @tag = tag + @error = error + super("my error message contains tag #{tag}") + end + + def to_s = "TagWrap #{@tag}" + end +end