<commit_before>from __future__ import absolute_import

from logging import Filter, Formatter
from logging.handlers import RotatingFileHandler, SMTPHandler

from flask import request

from oauthclientbridge import app


class ContextualFilter(Filter):
    def filter(self, log_record):
        log_record.request_path = request.path
        log_record.request_base_url = request.base_url
        log_record.request_method = request.method
        log_record.request_remote_address = request.remote_addr
        return True


class CustomSMTPHandler(SMTPHandler):
    def getSubject(self, record):  # noqa: N802
        return self.subject.format(record)


context_provider = ContextualFilter()
app.logger.addFilter(context_provider)
app.logger.setLevel('DEBUG')

if app.config['OAUTH_LOG_FILE']:
    file_handler = RotatingFileHandler(
        app.config['OAUTH_LOG_FILE'],
        maxBytes=app.config['OAUTH_LOG_FILE_MAX_BYTES'],
        backupCount=app.config['OAUTH_LOG_FILE_BACKUP_COUNT'])<commit_msg>Make sure there are no newlines in subject<commit_after>from __future__ import absolute_import

from logging import Filter, Formatter
from logging.handlers import RotatingFileHandler, SMTPHandler

from flask import request

from oauthclientbridge import app


class ContextualFilter(Filter):
    def filter(self, log_record):
        log_record.request_path = request.path
        log_record.request_base_url = request.base_url
        log_record.request_method = request.method
        log_record.request_remote_address = request.remote_addr
        return True


class CustomSMTPHandler(SMTPHandler):
    def getSubject(self, record):  # noqa: N802
        return self.subject.format(record).replace('\n', '')


context_provider = ContextualFilter()
app.logger.addFilter(context_provider)
app.logger.setLevel('DEBUG')

if app.config['OAUTH_LOG_FILE']:
    file_handler = RotatingFileHandler(
        app.config['OAUTH_LOG_FILE'],
        maxBytes=app.config['OAUTH_LOG_FILE_MAX_BYTES'],
        backupCount=app.config['OAUTH_LOG_FILE_BACKUP_COUNT'])
{'fraction_non_alphanumeric': 0.08126520681265206, 'fraction_numerical': 0.00291970802919708, 'mean_word_length': 4.632876712328767, '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': '6060099', 'n_tokens_mistral': 610, 'n_tokens_neox': 598, 'n_words': 120}