BlueBrain / BlueBrain/Atlas-Download-Tools
Control the logging level in the CLI
- Dominant language
- Python
- Stars
- 17
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
Regarding tracebacks / debugging, there are for sure different options.
First of all, we already have a way because we added the `__main__.py` file. So now to debug some `atldld ` command one just needs to write `python -m pdb -m atldld `. (I think one needs at least py37...)
And yes I've seen people using CLI flags to control the debug output. One could add something like `--debug`, `--log-level`, `-v`/`-vv`/`-vvv` directly to the root `atldld` command. For logging it would then configure the logging accordingly:
```python
import logging
logger = logging.getLogger(__name__)
@click.group()
@click.option('-v', '--verbose', count=True)
def root(verbose):
"""Run the command line interface for Atlas-Download-Tools."""
if verbose == 0:
log_level = logging.WARNING
elif verbose == 1:
log_level = logging.INFO
else: # verbose >= 2:
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
if verbose > 2:
logger.warning("The maximal verbosity is -vv")
@root.command("test")
def test():
logger.critical("Critical")
logger.error("Error")
logger.warning("Warning")
logger.info("Info")
logger.debug("Debug")
```
```bash
$ atldld test
CRITICAL:atldld.cli:Critical
ERROR:atldld.cli:Error
WARNING:atldld.cli:Warning
```
```bash
$ atldld -v test
CRITICAL:atldld.cli:Critical
ERROR:atldld.cli:Error
WARNING:atldld.cli:Warning
INFO:atldld.cli:Info
```
```bash
$ atldld -vv test
CRITICAL:atldld.cli:Critical
ERROR:atldld.cli:Error
WARNING:atldld.cli:Warning
INFO:atldld.cli:Info
DEBUG:atldld.cli:Debug
```
```bash
$ atldld -vvv test
WARNING:atldld.cli:The maximal verbosity is -vv
CRITICAL:atldld.cli:Critical
ERROR:atldld.cli:Error
WARNING:atldld.cli:Warning
INFO:atldld.cli:Info
DEBUG:atldld.cli:Debug
```
_Originally posted by @Stannislav in https://github.com/BlueBrain/Atlas-Download-Tools/pull/66#discussion_r698353401_
Contributor guide
Assessment
This issue has not been assessed yet.