<commit_before>from .message import Message
from .lib import iso8601time
import twiggy as _twiggy
import levels
import outputs
import formats

import sys
import time
import traceback
from functools import wraps

def emit(level):
    """a decorator that emits at ``level`` after calling the method. The method
    should return a Logger instance.

    For convenience, decorators for the various levels are available as
    ``emit.debug``, ``emit.info``, etc..

    """
    def decorator(f):
        @wraps(f)
        def wrapper(self, *args, **kwargs):
            f(self, *args, **kwargs)._emit(level)
        return wrapper
    return decorator

emit.debug = emit(levels.DEBUG)
emit.info = emit(levels.INFO)
emit.warning = emit(levels.WARNING)
emit.error = emit(levels.ERROR)
emit.critical = emit(levels.CRITICAL)

class BaseLogger(object):
    """Base class for loggers

    :ivar dict _fields: dictionary of bound fields for structured logging
    :ivar dict _options: dictionary of bound options. See `Message.options`.
    :ivar levels.Level min_level: minimum level for which to emit. For optimization purposes only.

    """


    __slots__ = ['_fields', '_options', 'min_level']

    __valid_options = set(Message._default_options)

    def __init__(self, fields = None, options = None, min_level = None):
        """Constructor for internal module use only, basically.

        ``fields`` and ``options`` will be copied.
        """
        self._fields = fields.copy() if fields is not None else {}
        self._options = options.copy() if options is not None else Message._default_options.copy()
        self.min_level = min_level if min_level is not None else levels.DEBUG

    def _clone(self):
        return self.__class__(fields = self._fields, options = self._options, min_level = self.min_level)

    def _emit(self):
        raise NotImplementedError

    ## The Magic
    def fields(self, **kwargs):
        """bind fields for structured logging"""
        clone = self._clone()
        clone._fields.update(kwargs)
        return clone

    def options(self, **kwargs):
        """bind options for message creation.  See `Message.options`"""
        bad_options = set(kwargs) - self.__valid_options
        if bad_options:
            raise ValueError("Invalid options {0!r}".format(tuple(bad_options)))
        clone = self._clone()
        clone._options.update(kwargs)<commit_msg>add fieldsDict<commit_after>from .message import Message
from .lib import iso8601time
import twiggy as _twiggy
import levels
import outputs
import formats

import sys
import time
import traceback
from functools import wraps

def emit(level):
    """a decorator that emits at ``level`` after calling the method. The method
    should return a Logger instance.

    For convenience, decorators for the various levels are available as
    ``emit.debug``, ``emit.info``, etc..

    """
    def decorator(f):
        @wraps(f)
        def wrapper(self, *args, **kwargs):
            f(self, *args, **kwargs)._emit(level)
        return wrapper
    return decorator

emit.debug = emit(levels.DEBUG)
emit.info = emit(levels.INFO)
emit.warning = emit(levels.WARNING)
emit.error = emit(levels.ERROR)
emit.critical = emit(levels.CRITICAL)

class BaseLogger(object):
    """Base class for loggers

    :ivar dict _fields: dictionary of bound fields for structured logging
    :ivar dict _options: dictionary of bound options. See `Message.options`.
    :ivar levels.Level min_level: minimum level for which to emit. For optimization purposes only.

    """


    __slots__ = ['_fields', '_options', 'min_level']

    __valid_options = set(Message._default_options)

    def __init__(self, fields = None, options = None, min_level = None):
        """Constructor for internal module use only, basically.

        ``fields`` and ``options`` will be copied.
        """
        self._fields = fields.copy() if fields is not None else {}
        self._options = options.copy() if options is not None else Message._default_options.copy()
        self.min_level = min_level if min_level is not None else levels.DEBUG

    def _clone(self):
        return self.__class__(fields = self._fields, options = self._options, min_level = self.min_level)

    def _emit(self):
        raise NotImplementedError

    ## The Magic
    def fields(self, **kwargs):
        """bind fields for structured logging"""
        return self.fieldsDict(kwargs)

    def fieldsDict(self, d):
        """bind fields for structured logging

        Use this instead of ``fields`` if you have keys which are not valid Python identifiers.

        :arg dict d: a dict of fields to bind
        """
        clone = self._clone()
        clone._fields.update(d)
        return clone

    def options(self, **kwargs):
        """bind options for message creation.  See `Message.options`"""
        bad_options = set(kwargs) - self.__valid_options
        if bad_options:
            raise ValueError("Invalid options {0!r}".format(tuple(bad_options)))
        clone = self._clone()
        clone._options.update(kwargs)
{'fraction_non_alphanumeric': 0.10159480212640283, 'fraction_numerical': 0.0019688915140775743, 'mean_word_length': 3.064, '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': '7011065', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1375, 'n_words': 484}