<commit_before>require "logging"
require "mongoid"

class MongoidAppender < Logging::Appender

	VERSION = "0.0.2"

	class Log
		include Mongoid::Document
		include Mongoid::Timestamps::Created

		store_in collection: "logs"

		field :level,		type: String
		field :logger,		type: String
		field :message,		type: String
		field :exception,	type: String
		field :backtrace,	type: Array

		index({ level: 1})
		index({ logger: 1})
		index({ exception: 1})
	end

	def initialize (name, opts = {})
    	super(name, opts)
 	end

	def write (event)
		if event.instance_of?(Logging::LogEvent)
			if event.data.is_a?(Exception)
				Log.create!(
					level: Logging::LNAMES[event.level],
					logger: event.logger,
					message: event.data.message,
					exception: event.data.class.to_s,
					backtrace: event.data.backtrace
				)
			else
				Log.create!(
					level: Logging::LNAMES[event.level],
					logger: event.logger,
					message: event.data.to_s
				)
			end
		else
			text = event.to_s

			Log.create!(
				level: text.split(" ")[0],
				logger: text.split(" ")[1],
				message: text[text.index(" : ") + 3..-1].split("\n\t")[0]
			) unless text.empty?
		end
	end
end<commit_msg>Bug fix in implementation for straight String logging<commit_after>require "logging"
require "mongoid"

class MongoidAppender < Logging::Appender

	VERSION = "0.0.3"

	class Log
		include Mongoid::Document
		include Mongoid::Timestamps::Created

		store_in collection: "logs"

		field :level,		type: String
		field :logger,		type: String
		field :message,		type: String
		field :exception,	type: String
		field :backtrace,	type: Array

		index({ level: 1})
		index({ logger: 1})
		index({ exception: 1})
	end

	def initialize (name, opts = {})
    	super(name, opts)
 	end

	def write (event)
		if event.instance_of?(Logging::LogEvent)
			if event.data.is_a?(Exception)
				Log.create!(
					level: Logging::LNAMES[event.level],
					logger: event.logger,
					message: event.data.message,
					exception: event.data.class.to_s,
					backtrace: event.data.backtrace
				)
			else
				Log.create!(
					level: Logging::LNAMES[event.level],
					logger: event.logger,
					message: event.data.to_s
				)
			end
		else
			Log.create!(message: event.to_s)
		end
	end
end
{'fraction_non_alphanumeric': 0.1301827909050379, 'fraction_numerical': 0.007579135086937138, 'mean_word_length': 3.282442748091603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2063594', 'n_tokens_mistral': 944, 'n_tokens_neox': 779, 'n_words': 194}