<commit_before>"""Django DDP logging helpers."""
from __future__ import absolute_import, print_function

import logging

from dddp import THREAD_LOCAL as this, meteor_random_id, ADDED


class DDPHandler(logging.Handler):

    """Logging handler that streams log events via DDP to the current client."""

    def emit(self, record):
        """Emit a formatted log record via DDP."""
        if getattr(this, 'subs', {}).get('Logs', False):
            this.send({
                'msg': ADDED,
                'collection': 'logs',
                'id': meteor_random_id('/collection/logs'),
                'fields': {
                    'name': record.name,
                    'levelno': record.levelno,
                    'levelname': record.levelname,
                    # 'pathname': record.pathname,
                    # 'lineno': record.lineno,
                    'msg': record.msg,
                    'args': record.args,
                    # 'exc_info': record.exc_info,
                    # 'funcName': record.funcName,
                },
            })<commit_msg>Fix bug in serialization of logging.LogRecord to show formatted message.<commit_after>"""Django DDP logging helpers."""
from __future__ import absolute_import, print_function

import datetime
import logging

from dddp import THREAD_LOCAL as this, meteor_random_id, ADDED


class DDPHandler(logging.Handler):

    """Logging handler that streams log events via DDP to the current client."""

    def emit(self, record):
        """Emit a formatted log record via DDP."""
        if getattr(this, 'subs', {}).get('Logs', False):
            this.send({
                'msg': ADDED,
                'collection': 'logs',
                'id': meteor_random_id('/collection/logs'),
                'fields': {
                    'created': datetime.datetime.fromtimestamp(record.created),
                    'name': record.name,
                    'levelno': record.levelno,
                    'levelname': record.levelname,
                    # 'pathname': record.pathname,
                    # 'lineno': record.lineno,
                    'msg': record.msg,
                    'args': record.args,
                    # 'exc_info': record.exc_info,
                    # 'funcName': record.funcName,
                },
            })
{'fraction_non_alphanumeric': 0.11665949203616013, 'fraction_numerical': 0.0, 'mean_word_length': 1.6991869918699187, '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': '5278853', 'n_tokens_mistral': 629, 'n_tokens_neox': 584, 'n_words': 161}