<commit_before>"""
Logging of tracebacks and L{twisted.python.failure.Failure} instances,
as well as common utilities for handling exception logging.
"""

from __future__ import unicode_literals

import types
import traceback
import sys
from warnings import warn

from six import exec_

from ._message import EXCEPTION_FIELD, REASON_FIELD
from ._util import safeunicode
from ._validation import MessageType, Field
from ._errors import _error_extraction

TRACEBACK_MESSAGE = MessageType(
    "eliot:traceback",
    [Field(REASON_FIELD, safeunicode, "The exception's value."),
     Field("traceback", safeunicode, "The traceback."),
     Field(EXCEPTION_FIELD,
           lambda typ: "%s.%s" % (typ.__module__, typ.__name__),
           "The exception type's FQPN.")],
    "An unexpected exception indicating a bug.")



def _writeTracebackMessage(logger, typ, exception, traceback):
    """
    Write a traceback to the log.

    @param typ: The class of the exception.

    @param exception: The L{Exception} instance.

    @param traceback: The traceback, a C{str}.<commit_msg>Note caveat about the type.<commit_after>"""
Logging of tracebacks and L{twisted.python.failure.Failure} instances,
as well as common utilities for handling exception logging.
"""

from __future__ import unicode_literals

import types
import traceback
import sys
from warnings import warn

from six import exec_

from ._message import EXCEPTION_FIELD, REASON_FIELD
from ._util import safeunicode
from ._validation import MessageType, Field
from ._errors import _error_extraction

# The fields here are actually subset of what you might get in practice,
# due to exception extraction, so don't rely on this for validation.
TRACEBACK_MESSAGE = MessageType(
    "eliot:traceback",
    [Field(REASON_FIELD, safeunicode, "The exception's value."),
     Field("traceback", safeunicode, "The traceback."),
     Field(EXCEPTION_FIELD,
           lambda typ: "%s.%s" % (typ.__module__, typ.__name__),
           "The exception type's FQPN.")],
    "An unexpected exception indicating a bug.")



def _writeTracebackMessage(logger, typ, exception, traceback):
    """
    Write a traceback to the log.

    @param typ: The class of the exception.

    @param exception: The L{Exception} instance.

    @param traceback: The traceback, a C{str}.
{'fraction_non_alphanumeric': 0.08780276816608996, 'fraction_numerical': 0.0, 'mean_word_length': 4.197752808988764, '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': '6301062', 'n_tokens_mistral': 674, 'n_tokens_neox': 643, 'n_words': 245}