-
Notifications
You must be signed in to change notification settings - Fork 0
Add SUPPRESS_ACCESS_LOGS setting and logging configuration tests #10
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
Changes from all commits
ebf77ab
3c108c8
6579801
fed1168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,3 +58,4 @@ test_fq.py | |
| .idea/* | ||
| venv/* | ||
| .vscode/ | ||
| .codex | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| * | ||
| !configs | ||
| !configs/** | ||
| !hooks | ||
| !hooks/** | ||
| !qlty.toml | ||
| !.gitignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ignored: | ||
| - DL3008 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # This file was automatically generated by `qlty init`. | ||
| # You can modify it to suit your needs. | ||
| # We recommend you to commit this file to your repository. | ||
| # | ||
| # This configuration is used by both Qlty CLI and Qlty Cloud. | ||
| # | ||
| # Qlty CLI -- Code quality toolkit for developers | ||
| # Qlty Cloud -- Fully automated Code Health Platform | ||
| # | ||
| # Try Qlty Cloud: https://qlty.sh | ||
| # | ||
| # For a guide to configuration, visit https://qlty.sh/d/config | ||
| # Or for a full reference, visit https://qlty.sh/d/qlty-toml | ||
| config_version = "0" | ||
|
|
||
| exclude_patterns = [ | ||
| "*_min.*", | ||
| "*-min.*", | ||
| "*.min.*", | ||
| "**/.yarn/**", | ||
| "**/*.d.ts", | ||
| "**/assets/**", | ||
| "**/bower_components/**", | ||
| "**/build/**", | ||
| "**/cache/**", | ||
| "**/config/**", | ||
| "**/db/**", | ||
| "**/deps/**", | ||
| "**/dist/**", | ||
| "**/extern/**", | ||
| "**/external/**", | ||
| "**/generated/**", | ||
| "**/Godeps/**", | ||
| "**/gradlew/**", | ||
| "**/mvnw/**", | ||
| "**/node_modules/**", | ||
| "**/protos/**", | ||
| "**/seed/**", | ||
| "**/target/**", | ||
| "**/templates/**", | ||
| "**/testdata/**", | ||
| "**/vendor/**", | ||
| ] | ||
|
|
||
| test_patterns = [ | ||
| "**/test/**", | ||
| "**/spec/**", | ||
| "**/*.test.*", | ||
| "**/*.spec.*", | ||
| "**/*_test.*", | ||
| "**/*_spec.*", | ||
| "**/test_*.*", | ||
| "**/spec_*.*", | ||
| ] | ||
|
|
||
| [smells] | ||
| mode = "comment" | ||
|
|
||
| [[source]] | ||
| name = "default" | ||
| default = true | ||
|
|
||
|
|
||
| [[plugin]] | ||
| name = "actionlint" | ||
|
|
||
| [[plugin]] | ||
| name = "bandit" | ||
|
|
||
| [[plugin]] | ||
| name = "hadolint" | ||
|
|
||
| [[plugin]] | ||
| name = "radarlint-iac" | ||
| mode = "monitor" | ||
|
|
||
| [[plugin]] | ||
| name = "radarlint-python" | ||
| mode = "comment" | ||
|
|
||
| [[plugin]] | ||
| name = "ripgrep" | ||
| mode = "comment" | ||
|
|
||
| [[plugin]] | ||
| name = "ruff" | ||
| drivers = [ | ||
| "lint", | ||
| ] | ||
|
|
||
| [[plugin]] | ||
| name = "trufflehog" | ||
|
|
||
| [[plugin]] | ||
| name = "zizmor" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright (c) 2025 Flowdacity Development Team. See LICENSE.txt for details. | ||
|
|
||
| import logging | ||
|
|
||
|
|
||
| def configure_logging( | ||
| log_level: str, | ||
| suppress_access_logs: bool = True, | ||
| ) -> None: | ||
| level = getattr(logging, log_level) | ||
| root_logger = logging.getLogger() | ||
|
|
||
| if not root_logger.handlers: | ||
| logging.basicConfig( | ||
| level=level, | ||
| format="%(asctime)s %(levelname)s [%(name)s] %(message)s", | ||
| ) | ||
|
|
||
| logging.getLogger("fq_server").setLevel(level) | ||
| logging.getLogger("uvicorn.access").disabled = suppress_access_logs |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||
| # Copyright (c) 2025 Flowdacity Development Team. See LICENSE.txt for details. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from fq_server.logging import configure_logging | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class TestLoggingConfig(unittest.TestCase): | ||||||||||||||||||||||||||||
| def setUp(self): | ||||||||||||||||||||||||||||
| self.root_logger = logging.getLogger() | ||||||||||||||||||||||||||||
| self.original_root_handlers = list(self.root_logger.handlers) | ||||||||||||||||||||||||||||
| self.original_root_level = self.root_logger.level | ||||||||||||||||||||||||||||
| self.fq_logger = logging.getLogger("fq_server") | ||||||||||||||||||||||||||||
| self.original_fq_level = self.fq_logger.level | ||||||||||||||||||||||||||||
| self.access_logger = logging.getLogger("uvicorn.access") | ||||||||||||||||||||||||||||
| self.original_disabled = self.access_logger.disabled | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def tearDown(self): | ||||||||||||||||||||||||||||
| for handler in list(self.root_logger.handlers): | ||||||||||||||||||||||||||||
| if handler not in self.original_root_handlers: | ||||||||||||||||||||||||||||
| self.root_logger.removeHandler(handler) | ||||||||||||||||||||||||||||
| handler.close() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.root_logger.setLevel(self.original_root_level) | ||||||||||||||||||||||||||||
| self.fq_logger.setLevel(self.original_fq_level) | ||||||||||||||||||||||||||||
| self.access_logger.disabled = self.original_disabled | ||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+27
|
||||||||||||||||||||||||||||
| self.original_disabled = self.access_logger.disabled | |
| def tearDown(self): | |
| self.access_logger.disabled = self.original_disabled | |
| self.original_disabled = self.access_logger.disabled | |
| self.root_logger = logging.getLogger() | |
| self.original_root_handlers = self.root_logger.handlers[:] | |
| self.original_root_level = self.root_logger.level | |
| def tearDown(self): | |
| self.access_logger.disabled = self.original_disabled | |
| self.root_logger.handlers[:] = self.original_root_handlers | |
| self.root_logger.setLevel(self.original_root_level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
configure_loggingfromasgitriggersasgi.pymodule import side effects (QueueServerSettings.from_env(),setup_server(...), andappconstruction). That makes this unit test heavier than needed and can introduce coupling to external dependencies (e.g., Flowdacity Queue / Redis behavior) unrelated to logging configuration. Consider movingconfigure_logginginto a side-effect-free module (e.g.,fq_server/logging.py) and importing it from bothasgi.pyand this test, or otherwise isolating app/server initialization from imports used by unit tests.