<commit_before># Copyright (C) 2007 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""Logging service setup.

STABLE.
"""

import array
import collections
import errno
import logging
import sys
import traceback
import os
import repr as repr_
import decorator

# Let's keep this module self contained so that it can be easily
# pasted in external sugar service like the datastore.

# traces function calls, use SUGAR_LOGGER_LEVEL=trace to enable
TRACE = 5
_LEVELS = {
    'error': logging.ERROR,
    'warning': logging.WARNING,
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'trace': TRACE,
    'all': 0,
}
logging.addLevelName(TRACE, 'TRACE')


def get_logs_dir():
    profile = os.environ.get('SUGAR_PROFILE', 'default')
    logs_dir = os.environ.get('SUGAR_LOGS_DIR',
                              os.path.join(os.path.expanduser('~'),
                                           '.sugar', profile, 'logs'))
    return logs_dir


def set_level(level):
    if level in _LEVELS:
        logging.getLogger('').setLevel(_LEVELS[level])
        return

    try:
        logging.getLogger('').setLevel(int(level))
    except ValueError:
        logging.warning('Invalid log level: %r', level)


# pylint: disable=E1101,F0401
def _except_hook(exctype, value, traceback):
    # Attempt to provide verbose IPython tracebacks.
    # Importing IPython is slow, so we import it lazily.
    try:
        from IPython.ultraTB import AutoFormattedTB
        sys.excepthook = AutoFormattedTB(mode='Verbose',
            color_scheme='NoColor')
    except ImportError:
        sys.excepthook = sys.__excepthook__

    sys.excepthook(exctype, value, traceback)


def start(log_filename=None):
    # remove existing handlers, or logging.basicConfig() won't have no effect.
    root_logger = logging.getLogger('')<commit_msg>pylint: sugar.logger: allow overriding module name<commit_after># Copyright (C) 2007 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""Logging service setup.

STABLE.
"""

import array
import collections
import errno
import logging
import sys
import traceback
import os
import repr as repr_
import decorator

# Let's keep this module self contained so that it can be easily
# pasted in external sugar service like the datastore.

# traces function calls, use SUGAR_LOGGER_LEVEL=trace to enable
TRACE = 5
_LEVELS = {
    'error': logging.ERROR,
    'warning': logging.WARNING,
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'trace': TRACE,
    'all': 0,
}
logging.addLevelName(TRACE, 'TRACE')


def get_logs_dir():
    profile = os.environ.get('SUGAR_PROFILE', 'default')
    logs_dir = os.environ.get('SUGAR_LOGS_DIR',
                              os.path.join(os.path.expanduser('~'),
                                           '.sugar', profile, 'logs'))
    return logs_dir


def set_level(level):
    if level in _LEVELS:
        logging.getLogger('').setLevel(_LEVELS[level])
        return

    try:
        logging.getLogger('').setLevel(int(level))
    except ValueError:
        logging.warning('Invalid log level: %r', level)


# pylint: disable=E1101,F0401,W0621
def _except_hook(exctype, value, traceback):
    # Attempt to provide verbose IPython tracebacks.
    # Importing IPython is slow, so we import it lazily.
    try:
        from IPython.ultraTB import AutoFormattedTB
        sys.excepthook = AutoFormattedTB(mode='Verbose',
            color_scheme='NoColor')
    except ImportError:
        sys.excepthook = sys.__excepthook__

    sys.excepthook(exctype, value, traceback)


def start(log_filename=None):
    # remove existing handlers, or logging.basicConfig() won't have no effect.
    root_logger = logging.getLogger('')
{'fraction_non_alphanumeric': 0.08963474827245804, 'fraction_numerical': 0.012240868706811452, 'mean_word_length': 3.371009490940466, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4511632', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1453, 'n_words': 544}