Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic logging configuration #93

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion spiderexpress/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,43 @@
"""
from importlib.metadata import entry_points
from pathlib import Path
from loguru import logger as log

import click
import yaml
import sys

from .spider import CONNECTOR_GROUP, STRATEGY_GROUP, Spider
from .types import Configuration


@click.group()
@click.pass_context
@log.catch
def cli(ctx):
"""Traverse the deserts of the internet."""
ctx.ensure_object(Spider)


@cli.command()
@click.argument("config", type=click.Path(path_type=Path, exists=True))
@click.option("-v", "--verbose", count=True)
@click.option("-l", "--logfile", type=click.Path(dir_okay=False, writable=True, path_type=str))
@click.pass_context
def start(ctx: click.Context, config: Path):
def start(ctx: click.Context, config: Path, verbose: int, logfile: str):
"""start a job"""
logging_level = max(50 - (10 * verbose), 0) # Allows logging level to be between 0 and 50.
logging_configuration = {
"handlers": [
{
"sink": logfile or sys.stdout,
"level": logging_level
}
],
"extra": {}
}
log.configure(**logging_configuration)
log.debug(f"Starting logging with verbosity {logging_level}.")
ctx.obj.start(config)


Expand Down
Loading