Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.44 KB

logging.rst

File metadata and controls

43 lines (31 loc) · 1.44 KB

Logging

strapp.logging

This is most useful when paired with setuplog or loguru.

  • Setuplog's setup_logging accepts a log_level_overrides argument who's format matches the output of this function.
  • Loguru's loguru.add function accepts a filter argument which who's format is compatible with the output of this function.

For use in applications, it's generally useful to call this as early as it is possible to have the level of verbosity you want.

For cli applications, this will tend to be inside the root cli group, where you accept the verbosity level.

import logging
import strapp.logging
from setuplog import setup_logging

package_verbosity = strapp.logging.package_verbosity_factory(
    ("urllib3", logging.INFO, logging.INFO, logging.INFO, logging.DEBUG),
    ("sqlalchemy.engine", logging.WARNING, logging.WARNING, logging.INFO, logging.DEBUG),
    ("docker", logging.INFO, logging.INFO, logging.INFO, logging.DEBUG),
)

@click.group()
@click.option('--verbose', count=True, default=0)
def cli(verbose):
    setup_logging(
        config.logging.level, log_level_overrides=package_verbosity(verbose),
    )

For flask apps, this tends to be even earlier, i.e. as soon as you load the config.