Refactor logging configuration to both Django management commands lintmigrations and makemigrations
This commit is contained in:
1 parent
26a8aaa993
commit
5f11f9417f
3 files changed
+18
-11
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import configparser
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from importlib import import_module
|
||||
@@ -12,7 +11,7 @@ from django.core.management.base import BaseCommand
|
||||
from ...constants import __version__
|
||||
from ...migration_linter import MessageType, MigrationLinter
|
||||
from ...sql_analyser.analyser import ANALYSER_STRING_MAPPING
|
||||
from ..utils import register_linting_configuration_options
|
||||
from ..utils import configure_logging, register_linting_configuration_options
|
||||
|
||||
CONFIG_NAME = "django_migration_linter"
|
||||
PYPROJECT_TOML = "pyproject.toml"
|
||||
@@ -22,8 +21,6 @@ DEFAULT_CONFIG_FILES = (
|
||||
"tox.ini",
|
||||
)
|
||||
|
||||
logger = logging.getLogger("django_migration_linter")
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Lint your migrations"
|
||||
@@ -145,12 +142,7 @@ class Command(BaseCommand):
|
||||
import_module(os.getenv("DJANGO_SETTINGS_MODULE")).__file__
|
||||
)
|
||||
|
||||
if options["verbosity"] > 1:
|
||||
logging.basicConfig(format="%(message)s", level=logging.DEBUG)
|
||||
elif options["verbosity"] == 0:
|
||||
logger.disabled = True
|
||||
else:
|
||||
logging.basicConfig(format="%(message)s")
|
||||
configure_logging(options["verbosity"])
|
||||
|
||||
django_settings_options = self.read_django_settings(options)
|
||||
config_options = self.read_config_file(options)
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.db.migrations.writer import MigrationWriter
|
||||
|
||||
from django_migration_linter import MigrationLinter
|
||||
|
||||
from ..utils import register_linting_configuration_options
|
||||
from ..utils import configure_logging, register_linting_configuration_options
|
||||
|
||||
|
||||
def ask_should_keep_migration():
|
||||
@@ -42,6 +42,7 @@ class Command(MakeMigrationsCommand):
|
||||
self.database = options["database"]
|
||||
self.exclude_migrations_tests = options["exclude_migration_tests"]
|
||||
self.warnings_as_errors = options["warnings_as_errors"]
|
||||
configure_logging(options["verbosity"])
|
||||
return super(Command, self).handle(*app_labels, **options)
|
||||
|
||||
def write_migration_files(self, changes):
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import logging
|
||||
|
||||
|
||||
def register_linting_configuration_options(parser):
|
||||
parser.add_argument(
|
||||
"--database",
|
||||
@@ -21,3 +24,14 @@ def register_linting_configuration_options(parser):
|
||||
action="store_true",
|
||||
help="handle warnings as errors",
|
||||
)
|
||||
|
||||
|
||||
def configure_logging(verbosity):
|
||||
logger = logging.getLogger("django_migration_linter")
|
||||
|
||||
if verbosity > 1:
|
||||
logging.basicConfig(format="%(message)s", level=logging.DEBUG)
|
||||
elif verbosity == 0:
|
||||
logger.disabled = True
|
||||
else:
|
||||
logging.basicConfig(format="%(message)s")
|
||||
Reference in new issue
Block a user