<commit_before>from __future__ import division, print_function, absolute_import

import logging
import bugsnag

class BugsnagHandler(logging.Handler):
    def __init__(self):
        logging.Handler.__init__(self)

        # To enable support for django we try to run the django configure here, but 
        # fail gracefully if we couldnt import or it was not configured properly
        try:
          import bugsnag.django
          bugsnag.django.configure()
        except:
          pass

    def emit(self, record):
        if record.exc_info:
            bugsnag.notify(record.exc_info)<commit_msg>Added better log handler support with severity<commit_after>from __future__ import division, print_function, absolute_import

import logging
import bugsnag

class BugsnagHandler(logging.Handler):
    def __init__(self, api_key=None):
        super(BugsnagHandler, self).__init__()

        # Check if API key has been specified.
        if not bugsnag.configuration.api_key and not api_key:
            raise Exception, "API key has not been configured or specified"

        # If API key specified in logger, always use this value, even if another
        # value was configured previously
        if api_key:
            bugsnag.configuration.api_key = api_key

    def emit(self, record):
        if record.levelname.lower() in ['error', 'critical']:
            severity = 'error'
        elif record.levelname.lower() in ['warning', ]:
            severity = 'warning'
        else:
            severity = 'info'

        if record.exc_info:
            bugsnag.notify(record.exc_info, severity=severity)
        else:
            exc = Exception(record.message)
            bugsnag.notify(exc, severity=severity)
{'fraction_non_alphanumeric': 0.07308584686774942, 'fraction_numerical': 0.0, 'mean_word_length': 2.5640495867768593, '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': '4696306', 'n_tokens_mistral': 470, 'n_tokens_neox': 454, 'n_words': 147}