<commit_before># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.
from flask import request

import os, string, copy
import logging.handlers, logging.config, logging
import ConfigParser

from MaKaC.common.Configuration import Config
from MaKaC.common.contextManager import ContextManager


class ExtraIndicoFilter(logging.Filter):

    def filter(self, record):
        if record.name.split('.')[0] == 'indico':
            return 0
        return 1


class IndicoMailFormatter(logging.Formatter):
    def format(self, record):
        s = logging.Formatter.format(self, record)
        return s + self._getRequestInfo()

    def _getRequestInfo(self):
        rh = ContextManager.get('currentRH', None)
        if not rh:
            return ''
        info = ['Additional information:']
        info.append('URL: %s' % rh.getRequestURL())
        info.append('Endpoint: %s' % request.url_rule.endpoint)
        info.append('Method: %s' % request.method)
        info.append('Params: %s' % rh._getTruncatedParams())
        info.append('IP: %s' % request.remote_addr)
        info.append('User Agent: %s' % request.user_agent)
        info.append('Referer: %s' % (request.referrer or 'n/a'))
        return '\n\n%s' % '\n'.join(info)


class LoggerUtils:

    @classmethod
    def _bootstrap_cp(cls, cp, defaultArgs):
        """
        Creates a very basic logging config for cases in which
        logging.conf does not yet exist<commit_msg>[IMP] Improve log details if no RH is active<commit_after># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.
from flask import request

import os, string, copy
import logging.handlers, logging.config, logging
import ConfigParser

from MaKaC.common.Configuration import Config
from MaKaC.common.contextManager import ContextManager


class ExtraIndicoFilter(logging.Filter):

    def filter(self, record):
        if record.name.split('.')[0] == 'indico':
            return 0
        return 1


class IndicoMailFormatter(logging.Formatter):
    def format(self, record):
        s = logging.Formatter.format(self, record)
        return s + self._getRequestInfo()

    def _getRequestInfo(self):
        rh = ContextManager.get('currentRH', None)
        info = ['Additional information:']
        info.append('URL: %s' % rh.getRequestURL() if rh else request.url)
        info.append('Endpoint: %s' % request.url_rule.endpoint)
        info.append('Method: %s' % request.method)
        if rh:
            info.append('Params: %s' % rh._getTruncatedParams())
        info.append('IP: %s' % request.remote_addr)
        info.append('User Agent: %s' % request.user_agent)
        info.append('Referer: %s' % (request.referrer or 'n/a'))
        return '\n\n%s' % '\n'.join(info)


class LoggerUtils:

    @classmethod
    def _bootstrap_cp(cls, cp, defaultArgs):
        """
        Creates a very basic logging config for cases in which
        logging.conf does not yet exist
{'fraction_non_alphanumeric': 0.11077981651376147, 'fraction_numerical': 0.005963302752293578, 'mean_word_length': 3.2713026444662097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5603390', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1199, 'n_words': 449}