<commit_before>import asyncio
import importlib
import logging
import os
import signal
import sys

import aioredis
from aioredis.pubsub import Receiver
import click
import structlog

from . import config_defaults
from .metrics import Metrics
from .receiver import ServiceReceiver


def setup_structlog(tty=False):
    processors = [
        structlog.stdlib.filter_by_level,
        structlog.processors.TimeStamper(fmt='iso', utc=True),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
    ]
    if tty:
        processors.append(structlog.dev.ConsoleRenderer())
    else:
        processors.append(structlog.processors.JSONRenderer())

    structlog.configure(
        processors=processors,
        context_class=dict,
        logger_factory=structlog.stdlib.LoggerFactory(),
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )


class SocketShark:
    def __init__(self, config):
        self.config = config
        self.log = structlog.get_logger().bind(pid=os.getpid())
        self._task = None
        self._shutdown = False
        self.sessions = set()
        self.metrics = Metrics(self)<commit_msg>Add logger and level to structlog<commit_after>import asyncio
import importlib
import logging
import os
import signal
import sys

import aioredis
from aioredis.pubsub import Receiver
import click
import structlog

from . import config_defaults
from .metrics import Metrics
from .receiver import ServiceReceiver


def setup_structlog(tty=False):
    processors = [
        structlog.stdlib.filter_by_level,
        structlog.stdlib.add_log_level,
        structlog.stdlib.add_logger_name,
        structlog.processors.TimeStamper(fmt='iso', utc=True),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
    ]
    if tty:
        processors.append(structlog.dev.ConsoleRenderer())
    else:
        processors.append(structlog.processors.JSONRenderer())

    structlog.configure(
        processors=processors,
        context_class=dict,
        logger_factory=structlog.stdlib.LoggerFactory(),
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )


class SocketShark:
    def __init__(self, config):
        self.config = config
        self.log = structlog.get_logger().bind(pid=os.getpid())
        self._task = None
        self._shutdown = False
        self.sessions = set()
        self.metrics = Metrics(self)
{'fraction_non_alphanumeric': 0.08286852589641434, 'fraction_numerical': 0.0, 'mean_word_length': 3.241554054054054, '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': '2724086', 'n_tokens_mistral': 741, 'n_tokens_neox': 725, 'n_words': 144}