From 8f9f862fbc8faaa486c3d8345cfc1404e3e74fc1 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 18 Apr 2024 15:31:39 -0700 Subject: [PATCH 1/5] chore: clean up console upon firing up the CLI Currently there's some irrelevant DEBUG-level type logging happening when using the CLI, here I'm doing the following things: - setting the default logging level to INFO, which is the normal/sane default usually used in software - downgrading unimportant messages in the console from INFO to DEBUG - adding a dash of color on the title (bolded-white) and config loading INFO (cyan) - turning off load limiter when not in a `production` environment (added a note to `UPDATING.md` for that) --- UPDATING.md | 2 ++ superset/cli/main.py | 2 +- superset/config.py | 12 ++++++++---- superset/utils/log.py | 2 +- superset/utils/logging_configurator.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/UPDATING.md b/UPDATING.md index 38c40bbdd0dfa..c19a49fdef1d8 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -41,6 +41,8 @@ assists people when migrating to a new version. - [27849](https://github.com/apache/superset/pull/27849/) More of an FYI, but we have a new config `SLACK_ENABLE_AVATARS` (False by default) that works in conjunction with set `SLACK_API_TOKEN` to fetch and serve Slack avatar links +- [??](https://github.com/apache/superset/pull/???/) The default logging level was changed + from DEBUG to INFO - which is the normal/sane default logging level for most software. ## 4.0.0 diff --git a/superset/cli/main.py b/superset/cli/main.py index d837d236d5b3f..10b60b5afea39 100755 --- a/superset/cli/main.py +++ b/superset/cli/main.py @@ -37,7 +37,7 @@ ) @with_appcontext def superset() -> None: - """This is a management script for the Superset application.""" + """\033[1;37mThe Apache Superset CLI\033[0m""" @app.shell_context_processor def make_shell_context() -> dict[str, Any]: diff --git a/superset/config.py b/superset/config.py index 787d52fa1453a..e91004e093107 100644 --- a/superset/config.py +++ b/superset/config.py @@ -37,6 +37,7 @@ from importlib.resources import files from typing import Any, Callable, Literal, TYPE_CHECKING, TypedDict +import click import pkg_resources from celery.schedules import crontab from flask import Blueprint @@ -271,7 +272,7 @@ def _try_json_readsha(filepath: str, length: int) -> str | None: # feature is on by default to make Superset secure by default, but you should # fine tune the limits to your needs. You can read more about the different # parameters here: https://flask-limiter.readthedocs.io/en/stable/configuration.html -RATELIMIT_ENABLED = True +RATELIMIT_ENABLED = True if os.environ.get("SUPERSET_ENV") == "production" else False RATELIMIT_APPLICATION = "50 per second" AUTH_RATE_LIMITED = True AUTH_RATE_LIMIT = "5 per second" @@ -844,7 +845,7 @@ class D3Format(TypedDict, total=False): # Console Log Settings LOG_FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s" -LOG_LEVEL = "DEBUG" +LOG_LEVEL = "INFO" # --------------------------------------------------- # Enable Time Rotate Log Handler @@ -1743,7 +1744,7 @@ class ExtraDynamicQueryFilters(TypedDict, total=False): if key.isupper(): setattr(module, key, getattr(override_conf, key)) - print(f"Loaded your LOCAL configuration at [{cfg_path}]") + click.secho(f"Loaded your LOCAL configuration at [{cfg_path}]", fg="cyan") except Exception: logger.exception( "Failed to import config for %s=%s", CONFIG_PATH_ENV_VAR, cfg_path @@ -1755,7 +1756,10 @@ class ExtraDynamicQueryFilters(TypedDict, total=False): import superset_config from superset_config import * # noqa: F403, F401 - print(f"Loaded your LOCAL configuration at [{superset_config.__file__}]") + click.secho( + f"Loaded your LOCAL configuration at [{superset_config.__file__}]", + fg="cyan", + ) except Exception: logger.exception("Found but failed to import local superset_config") raise diff --git a/superset/utils/log.py b/superset/utils/log.py index 1de599bf08233..9f60ae2e3f0dd 100644 --- a/superset/utils/log.py +++ b/superset/utils/log.py @@ -313,7 +313,7 @@ def get_event_logger_from_cfg_value(cfg_value: Any) -> AbstractEventLogger: "of superset.utils.log.AbstractEventLogger." ) - logging.info("Configured event logger of type %s", type(result)) + logging.debug("Configured event logger of type %s", type(result)) return cast(AbstractEventLogger, result) diff --git a/superset/utils/logging_configurator.py b/superset/utils/logging_configurator.py index 5753b3941ccf5..ba4bf2117f728 100644 --- a/superset/utils/logging_configurator.py +++ b/superset/utils/logging_configurator.py @@ -65,4 +65,4 @@ def configure_logging( ) logging.getLogger().addHandler(handler) - logger.info("logging was configured successfully") + logger.debug("logging was configured successfully") From 8b204cf4622accae143d9bb890f646edd77c4863 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 18 Apr 2024 15:37:42 -0700 Subject: [PATCH 2/5] add PR id in UPDATING --- UPDATING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPDATING.md b/UPDATING.md index c19a49fdef1d8..c7e00b44e1756 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -41,7 +41,7 @@ assists people when migrating to a new version. - [27849](https://github.com/apache/superset/pull/27849/) More of an FYI, but we have a new config `SLACK_ENABLE_AVATARS` (False by default) that works in conjunction with set `SLACK_API_TOKEN` to fetch and serve Slack avatar links -- [??](https://github.com/apache/superset/pull/???/) The default logging level was changed +- [28134](https://github.com/apache/superset/pull/28134/) The default logging level was changed from DEBUG to INFO - which is the normal/sane default logging level for most software. ## 4.0.0 From c03305c236a7a5e8bb7a6f7e3e3fe7ce8c0e9804 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 18 Apr 2024 15:39:33 -0700 Subject: [PATCH 3/5] comment about ANSI --- .pre-commit-config.yaml | 14 ++++++++++++++ superset/cli/main.py | 1 + 2 files changed, 15 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a476dc3ab1a3f..da054a96fdc12 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -95,3 +95,17 @@ repos: hooks: - id: helm-docs files: helm + - repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "-rn", # Only display messages + "-sn", # Don't display the score + "--rcfile=.pylintrc", # Link to your config file + "--load-plugins=pylint.extensions.docparams", # Load an extension + ] diff --git a/superset/cli/main.py b/superset/cli/main.py index 10b60b5afea39..aa7e3068f8b9d 100755 --- a/superset/cli/main.py +++ b/superset/cli/main.py @@ -38,6 +38,7 @@ @with_appcontext def superset() -> None: """\033[1;37mThe Apache Superset CLI\033[0m""" + # NOTE: codes above are ANSI color codes for bold white in CLI header ^^^ @app.shell_context_processor def make_shell_context() -> dict[str, Any]: From 2da98bda71a5396abf74a56274877068051f49ee Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 18 Apr 2024 18:12:55 -0700 Subject: [PATCH 4/5] linting --- .pre-commit-config.yaml | 14 -------------- superset/config.py | 3 ++- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da054a96fdc12..a476dc3ab1a3f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -95,17 +95,3 @@ repos: hooks: - id: helm-docs files: helm - - repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: system - types: [python] - args: - [ - "-rn", # Only display messages - "-sn", # Don't display the score - "--rcfile=.pylintrc", # Link to your config file - "--load-plugins=pylint.extensions.docparams", # Load an extension - ] diff --git a/superset/config.py b/superset/config.py index e91004e093107..20f884805bc00 100644 --- a/superset/config.py +++ b/superset/config.py @@ -20,6 +20,7 @@ in your PYTHONPATH as there is a ``from superset_config import *`` at the end of this file. """ + # mypy: ignore-errors # pylint: disable=too-many-lines from __future__ import annotations @@ -272,7 +273,7 @@ def _try_json_readsha(filepath: str, length: int) -> str | None: # feature is on by default to make Superset secure by default, but you should # fine tune the limits to your needs. You can read more about the different # parameters here: https://flask-limiter.readthedocs.io/en/stable/configuration.html -RATELIMIT_ENABLED = True if os.environ.get("SUPERSET_ENV") == "production" else False +RATELIMIT_ENABLED = os.environ.get("SUPERSET_ENV") == "production" RATELIMIT_APPLICATION = "50 per second" AUTH_RATE_LIMITED = True AUTH_RATE_LIMIT = "5 per second" From ac043ba3d5914e9f964c49c018037baf260c3e46 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 23 Apr 2024 11:10:00 -0700 Subject: [PATCH 5/5] set default logging levels to logging.INFO --- superset/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/config.py b/superset/config.py index 20f884805bc00..4cd2590bd7a4d 100644 --- a/superset/config.py +++ b/superset/config.py @@ -846,7 +846,7 @@ class D3Format(TypedDict, total=False): # Console Log Settings LOG_FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s" -LOG_LEVEL = "INFO" +LOG_LEVEL = logging.INFO # --------------------------------------------------- # Enable Time Rotate Log Handler @@ -854,7 +854,7 @@ class D3Format(TypedDict, total=False): # LOG_LEVEL = DEBUG, INFO, WARNING, ERROR, CRITICAL ENABLE_TIME_ROTATE = False -TIME_ROTATE_LOG_LEVEL = "DEBUG" +TIME_ROTATE_LOG_LEVEL = logging.INFO FILENAME = os.path.join(DATA_DIR, "superset.log") ROLLOVER = "midnight" INTERVAL = 1