<commit_before>import logging
# makes it possible to `import ircbot.log` for global access to application logging
log = logging.getLogger(__name__)

import importlib
import sys
import yaml

import ircbot.irc
import ircbot.bot
import ircbot.plugin

# makes it possible to `import ircbot.cfg` for global access to the config dict
cfg = {}

def run_bot(storage_dir, yml_config):
	global cfg

	with open(yml_config, 'r') as f:
		cfg = yaml.load(f.read())

	# read the logging level from the config file, defaulting to INFO
	log_level = logging.INFO
	if 'log_level' in cfg:
		log_level = getattr(logging, cfg.get('log_level').upper())
	_configure_logging(log_level)

	# initialize the bot object
	bot = ircbot.bot.Bot(
		storage_dir = storage_dir,
		global_plugins = cfg.get('global_plugins', []),
		**cfg.get('bot', {})
	)

	_configure_plugins(bot, cfg.get('plugins', {}))
	_configure_channels(bot, cfg.get('channels', {}))

	# infinite loop go!
	bot.run_forever()


def _configure_logging(log_level):
	# set the level
	root = logging.getLogger()
	root.setLevel(log_level)

	# add a handler that prints to stdout
	ch = logging.StreamHandler(sys.stdout)
	ch.setLevel(log_level)

	# define the logging format
	formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
	ch.setFormatter(formatter)

	# add the logging handler for all loggers
	root.addHandler(ch)


def _configure_plugins(bot, plugins_dict):
	for name, plugin_class in plugins_dict.items():
		# dynamically import the plugin module and pass the class
		parts = plugin_class.split('.')
		module = importlib.import_module('.'.join(parts[:-1]))
		plugin_class = getattr(module, parts[-1])
		bot.register_plugin(name, plugin_class)
<commit_msg>configurable log path<commit_after>import logging
# makes it possible to `import ircbot.log` for global access to application logging
log = logging.getLogger(__name__)

import importlib
import sys
import yaml

import ircbot.irc
import ircbot.bot
import ircbot.plugin

# makes it possible to `import ircbot.cfg` for global access to the config dict
cfg = {}

def run_bot(storage_dir, yml_config):
	global cfg

	with open(yml_config, 'r') as f:
		cfg = yaml.load(f.read())

	# read the logging level from the config file, defaulting to INFO
	log_level = logging.INFO
	if 'log_level' in cfg:
		log_level = getattr(logging, cfg.get('log_level').upper())
	_configure_logging(log_level, cfg.get('log_path'))

	# initialize the bot object
	bot = ircbot.bot.Bot(
		storage_dir = storage_dir,
		global_plugins = cfg.get('global_plugins', []),
		**cfg.get('bot', {})
	)

	_configure_plugins(bot, cfg.get('plugins', {}))
	_configure_channels(bot, cfg.get('channels', {}))

	# infinite loop go!
	bot.run_forever()


def _configure_logging(log_level, log_path=None):
	# set the level
	root = logging.getLogger()
	root.setLevel(log_level)

	if log_path is None:
		ch = logging.StreamHandler(sys.stdout)
	else:
		ch = logging.StreamHandler(log_path)
	ch.setLevel(log_level)

	# define the logging format
	formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
	ch.setFormatter(formatter)

	# add the logging handler for all loggers
	root.addHandler(ch)


def _configure_plugins(bot, plugins_dict):
	for name, plugin_class in plugins_dict.items():
		# dynamically import the plugin module and pass the class
		parts = plugin_class.split('.')
		module = importlib.import_module('.'.join(parts[:-1]))
		plugin_class = getattr(module, parts[-1])
		bot.register_plugin(name, plugin_class)

{'fraction_non_alphanumeric': 0.11996596710153148, 'fraction_numerical': 0.0011344299489506524, 'mean_word_length': 5.008517887563884, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4509056', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1170, 'n_words': 316}