teald / rst_extract

Extract python code from rst documents, and output it into a single file.
GNU General Public License v3.0
0 stars 0 forks source link

Logging should eventually live in a separate file. #11

Open github-actions[bot] opened 4 months ago

github-actions[bot] commented 4 months ago

@click.command()

@_VERBOSE_OPTION

def configure_logging(verbose: int) -> None:

https://github.com/teald/rst_extract/blob/481dfada50d42af10b6da03be751a1ef0a843875/rst_extract/cli.py#L38


To-do
-----
- [ ] Implement an interactive selector for multiple files.
- [x] Implement a flag for verbosity.
    - [x] -v for INFO
    - [x] -vv for DEBUG
    - [x] default to WARNING
    - [ ] Make output handled with this, too, so there's not undesirable stdout
          output without being requested.
- [ ] Implement a debug mode.
- [ ] Implement a version flag.
- [ ] Implement a flag to output to a file.
- [ ] Implement a flag to output log messages to a file.
"""

import logging
import os
import sys

import click
import structlog
from structlog.stdlib import LoggerFactory

from .extractor import Extractor

_VERBOSE_OPTION = click.option(
    '-v',
    '--verbose',
    default=0,
    type=int,
    count=True,
    help='Increase verbosity. Can be used multiple times. Maximum is DEBUG (-vvv).',
)

# TODO: Logging should eventually live in a separate file.
@click.command()
@_VERBOSE_OPTION
def configure_logging(verbose: int) -> None:
    """Configure logging for rst_extract."""
    if not verbose:
        level = logging.WARNING

    elif verbose == 1:
        level = logging.INFO

    elif verbose == 2:
        level = logging.DEBUG

    logging.basicConfig(
        format='%(message)s',
        stream=sys.stdout,
        level=level,
    )

    structlog.configure(
        processors=[
            structlog.processors.TimeStamper(fmt='iso'),
            structlog.processors.StackInfoRenderer(),
            structlog.processors.format_exc_info,
            structlog.processors.UnicodeDecoder(),
            structlog.processors.ExceptionPrettyPrinter(),
            structlog.processors.JSONRenderer(),
        ],
        context_class=dict,
        logger_factory=LoggerFactory(),
        wrapper_class=structlog.BoundLogger,
        cache_logger_on_first_use=True,
    )

MAGNIFYING_GLASS = '\U0001f50d'
EXCLAMATION_MARK = '\U00002757'