<commit_before>import logging
import re
import traceback

import sys

import colored

import datetime

from dnutils.debug import _caller

DEBUG = logging.DEBUG
INFO = logging.INFO
WARNING = logging.WARNING
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL

FileHandler = logging.FileHandler
StreamHandler = logging.StreamHandler


class _LoggerAdapter(object):
    def __init__(self, logger):
        self._logger = logger
        self._logger.findCaller = self._caller

    def _caller(self, _):
        return _caller(4)

    def critical(self, *args, **kwargs):
        self._logger.critical(' '.join(map(str, args)), extra=kwargs)

    def exception(self, *args, **kwargs):
        self._logger.exception(' '.join(map(str, args)), extra=kwargs)

    def error(self, *args, **kwargs):
        self._logger.error(' '.join(map(str, args)), extra=kwargs)

    def warning(self, *args, **kwargs):
        self._logger.warning(' '.join(map(str, args)), extra=kwargs)

    def info(self, *args, **kwargs):
        self._logger.info(' '.join(map(str, args)), extra=kwargs)

    def debug(self, *args, **kwargs):
        self._logger.debug(' '.join(map(str, args)), extra=kwargs)

    def __getattr__(self, attr):
        return getattr(self._logger, attr)

    @property
    def level(self):
        return self._logger.level

    @level.setter
    def level(self, l):
        self._logger.setLevel(l)

    def add_handler(self, h):
        self._logger.addHandler(h)

    def rm_handler(self, h):
        self._logger.removeHandler(h)

    @property
    def handlers(self):
        return self._logger.handlers

    def new(self, name, level=None):
        '''
        Spawn a new logger with the given name and return it.

        The new logger will be a child logger of this logger, i.e. it will inherit all of its handlers and,
        if not specified by the level parameter, also the log level.

        :param name:
        :param level:
        :return:
        '''
        if level is None:
            level = self.level
        logger = logging.getLogger(name)
        logger.parent = self._logger
        logger._initialized = True
        logger.setLevel(level)
        return _LoggerAdapter(logger)


def loglevel(level, name=None):
    if name is None:
        name = ''
    getlogger(name).level = level


ansi_escape = re.compile(r'\x1b[^m]*m')


def cleanstr(s):
    return ansi_escape.sub('', s)

<commit_msg>function for listing all registered loggers<commit_after>import logging
import re
import traceback

import sys

import colored

import datetime

from dnutils.debug import _caller, out

DEBUG = logging.DEBUG
INFO = logging.INFO
WARNING = logging.WARNING
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL

FileHandler = logging.FileHandler
StreamHandler = logging.StreamHandler


class _LoggerAdapter(object):
    def __init__(self, logger):
        self._logger = logger
        self._logger.findCaller = self._caller

    def _caller(self, _):
        return _caller(4)

    def critical(self, *args, **kwargs):
        self._logger.critical(' '.join(map(str, args)), extra=kwargs)

    def exception(self, *args, **kwargs):
        self._logger.exception(' '.join(map(str, args)), extra=kwargs)

    def error(self, *args, **kwargs):
        self._logger.error(' '.join(map(str, args)), extra=kwargs)

    def warning(self, *args, **kwargs):
        self._logger.warning(' '.join(map(str, args)), extra=kwargs)

    def info(self, *args, **kwargs):
        self._logger.info(' '.join(map(str, args)), extra=kwargs)

    def debug(self, *args, **kwargs):
        self._logger.debug(' '.join(map(str, args)), extra=kwargs)

    def __getattr__(self, attr):
        return getattr(self._logger, attr)

    @property
    def level(self):
        return self._logger.level

    @level.setter
    def level(self, l):
        self._logger.setLevel(l)

    @property
    def name(self):
        return self._logger.name

    def add_handler(self, h):
        self._logger.addHandler(h)

    def rm_handler(self, h):
        self._logger.removeHandler(h)

    @property
    def handlers(self):
        return self._logger.handlers

    def new(self, name, level=None):
        '''
        Spawn a new logger with the given name and return it.

        The new logger will be a child logger of this logger, i.e. it will inherit all of its handlers and,
        if not specified by the level parameter, also the log level.

        :param name:
        :param level:
        :return:
        '''
        if level is None:
            level = self.level
        logger = logging.getLogger(name)
        logger.parent = self._logger
        logger._initialized = True
        logger.setLevel(level)
        return _LoggerAdapter(logger)

    def __str__(self):
        return '<LoggerAdapter name="%s", level=%s>' % (self.name, logging._levelToName[self.level])

def getloggers():
    with logging._lock:
        for name in logging.Logger.manager.loggerDict:
            yield getlogger(name)

def loglevel(level, name=None):
    if name is None:
        name = ''
    getlogger(name).level = level


ansi_escape = re.compile(r'\x1b[^m]*m')


def cleanstr(s):
    return ansi_escape.sub('', s)


{'fraction_non_alphanumeric': 0.11921674025724707, 'fraction_numerical': 0.0007679017085813016, 'mean_word_length': 2.759018759018759, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1822959', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1543, 'n_words': 435}