From ae336d20332224476f4916758c9e6867bcc1a896 Mon Sep 17 00:00:00 2001 From: peterbppb <91122533+peterbppb@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:25:16 +0200 Subject: [PATCH 1/4] custom output should account for the current verbosity level (#7) * custom output should account for the current verbosity level Signed-off-by: peterbppb <91122533+peterbppb@users.noreply.github.com> --------- Signed-off-by: peterbppb <91122533+peterbppb@users.noreply.github.com> Co-authored-by: Gustavo Silva Co-authored-by: Bogdan Peter --- logbasecommand/__init__.py | 2 +- logbasecommand/base.py | 28 +++++++++++++++++----------- testapp/testapp/urls.py | 3 ++- testapp/tests/test_command.py | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/logbasecommand/__init__.py b/logbasecommand/__init__.py index d18f409..27fdca4 100644 --- a/logbasecommand/__init__.py +++ b/logbasecommand/__init__.py @@ -1 +1 @@ -__version__ = '0.0.2' +__version__ = "0.0.3" diff --git a/logbasecommand/base.py b/logbasecommand/base.py index f92c7eb..237e835 100644 --- a/logbasecommand/base.py +++ b/logbasecommand/base.py @@ -14,8 +14,8 @@ class LogBaseCommand(BaseCommand): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - prefix = getattr(settings, 'LOGBASECOMMAND_PREFIX', None) or __name__ - self.logger = logging.getLogger(prefix + '.' + self.__module__.split('.')[-1]) + prefix = getattr(settings, "LOGBASECOMMAND_PREFIX", None) or __name__ + self.logger = logging.getLogger(prefix + "." + self.__module__.split(".")[-1]) def __handle_custom_std(self, ifstd, std, msg, *args): if ifstd: @@ -33,15 +33,18 @@ def log_debug(self, msg, *args, **kwargs): return self.logger.debug(msg, *args, **kwargs) def log(self, msg, *args, **kwargs): - self.__custom_stdout(msg, *args) + if self.logger.level <= logging.INFO: + self.__custom_stdout(msg, *args) return self.logger.info(msg, *args, **kwargs) def log_warning(self, msg, *args, **kwargs): - self.__custom_stderr(msg, *args) + if self.logger.level <= logging.WARNING: + self.__custom_stderr(msg, *args) return self.logger.warning(msg, *args, **kwargs) def log_error(self, msg, *args, **kwargs): - self.__custom_stderr(msg, *args) + if self.logger.level <= logging.ERROR: + self.__custom_stderr(msg, *args) return self.logger.error(msg, *args, **kwargs) def log_exception(self, msg, *args, **kwargs): @@ -49,16 +52,19 @@ def log_exception(self, msg, *args, **kwargs): return self.logger.exception(msg, *args, **kwargs) def execute(self, *args, **options): - self.verbosity = options['verbosity'] + self.verbosity = options["verbosity"] self.logger.setLevel( - [logging.ERROR, max(self.logger.getEffectiveLevel(), logging.INFO), logging.DEBUG, logging.DEBUG][ - self.verbosity - ] + [ + logging.ERROR, + max(self.logger.getEffectiveLevel(), logging.INFO), + logging.DEBUG, + logging.DEBUG, + ][self.verbosity] ) - if options.get('stdout') is not None: + if options.get("stdout") is not None: self.custom_stdout = True - if options.get('stderr') is not None: + if options.get("stderr") is not None: self.custom_stderr = True super().execute(*args, **options) diff --git a/testapp/testapp/urls.py b/testapp/testapp/urls.py index 8ab3632..ab2af97 100644 --- a/testapp/testapp/urls.py +++ b/testapp/testapp/urls.py @@ -13,9 +13,10 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin from django.urls import path urlpatterns = [ - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), ] diff --git a/testapp/tests/test_command.py b/testapp/tests/test_command.py index 6e6e38b..c30bef3 100644 --- a/testapp/tests/test_command.py +++ b/testapp/tests/test_command.py @@ -25,5 +25,5 @@ def test_silent(self): out = StringIO() err = StringIO() call_command('some_command', verbosity=0, stdout=out, stderr=err) - self.assertEqual(out.getvalue(), 'info message\n') + self.assertEqual(out.getvalue(), '') self.assertEqual(err.getvalue(), 'error message\nexception handled\n') From bf17d755b817bc3e6c69ca9b425ad58a2d16023e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:53:01 +0000 Subject: [PATCH 2/4] build(deps): bump black from 20.8b1 to 24.3.0 in /testapp Bumps [black](https://github.com/psf/black) from 20.8b1 to 24.3.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/commits/24.3.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- testapp/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testapp/requirements.txt b/testapp/requirements.txt index a7b5362..c063619 100644 --- a/testapp/requirements.txt +++ b/testapp/requirements.txt @@ -2,4 +2,4 @@ pytest==6.2.5 pytest-cov==2.12.1 pytest-django==4.4.0 -black==20.8b1 +black==24.3.0 From c2acbd00afff0d3114c9d480ab386ac3a1cd11e5 Mon Sep 17 00:00:00 2001 From: peterbppb <91122533+peterbppb@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:57:50 +0200 Subject: [PATCH 3/4] Change set level to allow for all possible verbosity levels to be set (#10) Co-authored-by: Bogdan Peter --- logbasecommand/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logbasecommand/base.py b/logbasecommand/base.py index 237e835..38c44c7 100644 --- a/logbasecommand/base.py +++ b/logbasecommand/base.py @@ -56,8 +56,8 @@ def execute(self, *args, **options): self.logger.setLevel( [ logging.ERROR, - max(self.logger.getEffectiveLevel(), logging.INFO), - logging.DEBUG, + logging.INFO, + logging.WARNING, logging.DEBUG, ][self.verbosity] ) From c9e0e9384bb3037866ce18d245727bfc75bf1445 Mon Sep 17 00:00:00 2001 From: Bogdan Peter Date: Thu, 28 Mar 2024 11:59:01 +0200 Subject: [PATCH 4/4] v0.0.4 --- logbasecommand/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logbasecommand/__init__.py b/logbasecommand/__init__.py index 27fdca4..81f0fde 100644 --- a/logbasecommand/__init__.py +++ b/logbasecommand/__init__.py @@ -1 +1 @@ -__version__ = "0.0.3" +__version__ = "0.0.4"