<commit_before>module ExceptionHandler
	module Parser
		class Save

			#Init
			def initialize(exception, request, controller)
				@exception, @request, @controller = exception, request, controller
			end

			#Save
			def save
				ActiveRecord::Base.logger.silence do
					ExceptionHandler::Error.create(relevant_info)
				end
	 			log(relevant_info)
			end

			#Info
			def relevant_info(info = {})
				info[:class_name] 	= @exception.class.to_s
				info[:message] 		= @exception.to_s
				info[:trace] 		= @exception.backtrace.join("\n")
				info[:target_url] 	= @request.url
				info[:referer_url] 	= @request.referer
				info[:params] 		= @request.params.inspect
				info[:user_agent] 	= @request.user_agent
				if user
					info[:usable_type] 	= user[:type]
					info[:usable_id] 	= user[:id]
				end
				return info
			end

			#User
			def user(data = {})
				# => refer to Joe's if want to find admin / user
				if @controller.respond_to?(:current_user)
					user = @controller.send :current_user
					[:id].each do |field|
						data[:id] = user.send(field) 	if user.respond_to?(field)
						data[:type] = "User" 			if @controller.respond_to?("current_user")
					end
				end
				return data
			end

			#Log
			def log(info)
				message = "#{info[:class_name]} (#{info[:message]}):\n "
				message += Rails.backtrace_cleaner.clean(info[:trace].split("\n")).join("\n")
				Rails.logger.fatal(message)
			end

		end
	end
end<commit_msg>Save Mechanism<commit_after>module ExceptionHandler
	module Parser
		class Save

			#Init
			def initialize(exception, request, controller)
				@exception, @request, @controller, @user = exception, request, controller, user
			end

			#Save
			def save
				#http://blog.habanerohq.com/post/16800611137/selectively-silence-activerecord-logging
				message = ""
				ActiveRecord::Base.logger.silence do
					ExceptionHandler::Error.create info do |error|
						message += "#{error.class_name}:\n "
						#message += Rails.backtrace_cleaner.clean(error.trace.split("\n")).join("\n")
					end
				end
				Rails.logger.fatal message unless message.blank?
				Rails.logger.info info[:usable_type]
			end

			private

			#User
			def user
				@controller.send(:current_user) if @controller.respond_to?(:current_user)
			end

			#Info
			def info
				info = {
					class_name: 	@exception.class.to_s,
					message: 		@exception.to_s,
					trace: 			@exception.backtrace.join("\n"),
					target_url: 	@request.url,
					referer_url: 	@request.referer,
					params: 		@request.params.inspect,
					user_agent: 	@request.user_agent
				}
				if @user && @user.respond_to(:id)
					info[:usable_type] 	= @user.model_name.human
					info[:usable_id] 	= @user.id
				end
				return info
			end

		end
	end
end
{'fraction_non_alphanumeric': 0.12828947368421054, 'fraction_numerical': 0.00402046783625731, 'mean_word_length': 3.048816568047337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195610', 'n_tokens_mistral': 1213, 'n_tokens_neox': 929, 'n_words': 184}