<commit_before>__all__ = [
    'LoggingComponent',
]

import logging
import threading

import garage
from garage import components


class LoggingComponent(components.Component):

    TRACE = logging.DEBUG - 1

    LOG_FORMAT = (
        '%(asctime)s %(threadName)s %(levelname)s %(name)s: %(message)s'
    )

    require = components.ARGS

    def __init__(self, verbose=0):
        self.verbose = verbose

    def add_arguments(self, parser):
        group = parser.add_argument_group(garage.__name__)
        group.add_argument(
            '-v', '--verbose', action='count', default=self.verbose,
            help='verbose output')

    def make(self, require):
        args = require.args
        logging.addLevelName(self.TRACE, 'TRACE')
        if args.verbose == 0:
            level = logging.WARNING
        elif args.verbose == 1:
            level = logging.INFO
        elif args.verbose == 2:
            level = logging.DEBUG
        else:
            level = self.TRACE
        logging.basicConfig(level=level, format=self.LOG_FORMAT)
        threading.current_thread().name = garage.__name__ + '#main'

    # Hack for manipulating startup order.
    add_arguments.__module__ = garage.__name__
    make.__module__ = garage.__name__<commit_msg>Use DEBUG environ variable<commit_after>__all__ = [
    'LoggingComponent',
]

import logging
import os
import threading

import garage
from garage import components


class LoggingComponent(components.Component):

    TRACE = logging.DEBUG - 1

    LOG_FORMAT = (
        '%(asctime)s %(threadName)s %(levelname)s %(name)s: %(message)s'
    )

    require = components.ARGS

    def __init__(self, verbose=0):
        self.verbose = verbose

    def add_arguments(self, parser):
        group = parser.add_argument_group(garage.__name__)
        group.add_argument(
            '-v', '--verbose', action='count', default=self.verbose,
            help='verbose output')

    def make(self, require):
        args = require.args
        if args.verbose == 0:
            level = logging.WARNING
        elif args.verbose == 1:
            level = logging.INFO
        elif args.verbose == 2:
            level = logging.DEBUG
        else:
            level = self.TRACE
        self.configure(level)

    @classmethod
    def configure(cls, level):
        logging.addLevelName(cls.TRACE, 'TRACE')
        logging.basicConfig(level=level, format=cls.LOG_FORMAT)
        threading.current_thread().name = garage.__name__ + '#main'

    # Hack for manipulating startup order.
    add_arguments.__module__ = garage.__name__
    make.__module__ = garage.__name__


if os.environ.get('DEBUG') not in (None, '', '0'):
    LoggingComponent.configure(logging.DEBUG)
    logging.getLogger(__name__).debug('start at DEBUG level')
{'fraction_non_alphanumeric': 0.1104713925872616, 'fraction_numerical': 0.00395825836631882, 'mean_word_length': 2.587096774193548, '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': '2981202', 'n_tokens_mistral': 816, 'n_tokens_neox': 781, 'n_words': 182}