Skip to content

Commit 0ddb210

Browse files
committed
feat: quiet-logs flag
1 parent 272a40c commit 0ddb210

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

elementary/cli/cli.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def get_log_path(ctx):
2929
return os.path.join(target_path, "edr.log")
3030

3131

32+
def get_quiet_logs(ctx):
33+
try:
34+
ctx_args = ctx.args
35+
idx = ctx_args.index("--quiet-logs")
36+
return ctx_args[idx + 1].lower() == "true"
37+
except (ValueError, IndexError):
38+
return False
39+
40+
3241
class ElementaryCLI(click.MultiCommand):
3342
_CMD_MAP = {
3443
"monitor": monitor,
@@ -57,12 +66,14 @@ def format_help(self, ctx, formatter):
5766

5867
def invoke(self, ctx: click.Context) -> Any:
5968
files_target_path = get_log_path(ctx)
60-
set_root_logger_handlers("elementary", files_target_path)
61-
click.echo(
62-
"Any feedback and suggestions are welcomed! join our community here - "
63-
"https://bit.ly/slack-elementary\n"
64-
)
65-
logger.info(f"Running with edr={package.get_package_version()}")
69+
quiet_logs = get_quiet_logs(ctx)
70+
set_root_logger_handlers("elementary", files_target_path, quiet_logs=quiet_logs)
71+
if not quiet_logs:
72+
click.echo(
73+
"Any feedback and suggestions are welcomed! join our community here - "
74+
"https://bit.ly/slack-elementary\n"
75+
)
76+
logger.info(f"Running with edr={package.get_package_version()}")
6677
return super().invoke(ctx)
6778

6879

elementary/monitor/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def decorator(func):
149149
else "DEPRECATED! Please use --filters instead! - Filter the alerts by tags:<TAGS> / owners:<OWNERS> / models:<MODELS> / "
150150
"statuses:<warn/fail/error/skipped> / resource_types:<model/test>.",
151151
)(func)
152+
func = click.option(
153+
"--quiet-logs",
154+
type=bool,
155+
default=False,
156+
help="Minimize INFO level logs. Only WARNING and above will be shown.",
157+
)(func)
152158
return func
153159

154160
return decorator
@@ -324,12 +330,14 @@ def monitor(
324330
excludes,
325331
teams_webhook,
326332
maximum_columns_in_alert_samples,
333+
quiet_logs,
327334
):
328335
"""
329336
Get alerts on failures in dbt jobs.
330337
"""
331338
if ctx.invoked_subcommand is not None:
332339
return
340+
333341
if deprecated_slack_webhook is not None:
334342
click.secho(
335343
'\n"-s" is deprecated and won\'t be supported in the near future.\n'
@@ -450,6 +458,7 @@ def report(
450458
env,
451459
select,
452460
target_path,
461+
quiet_logs,
453462
):
454463
"""
455464
Generate a local observability report of your warehouse.
@@ -680,6 +689,7 @@ def send_report(
680689
disable,
681690
include,
682691
target_path,
692+
quiet_logs,
683693
):
684694
"""
685695
Generate and send the report to an external platform.

elementary/monitor/fetchers/alerts/alerts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
from typing import Dict, List, Optional
33

4+
import click
5+
46
from elementary.clients.dbt.base_dbt_runner import BaseDbtRunner
57
from elementary.clients.fetcher.fetcher import FetcherClient
68
from elementary.config.config import Config
@@ -29,7 +31,7 @@ def skip_alerts(
2931
):
3032
alert_ids = [alert.id for alert in alerts_to_skip]
3133
alert_ids_chunks = self._split_list_to_chunks(alert_ids)
32-
logger.info("Update skipped alerts")
34+
click.echo(f"Update skipped alerts ({len(alerts_to_skip)})")
3335
for alert_ids_chunk in alert_ids_chunks:
3436
self.dbt_runner.run(
3537
select="elementary_cli.update_alerts.update_skipped_alerts",
@@ -60,7 +62,7 @@ def query_last_alert_times(
6062

6163
def update_sent_alerts(self, alert_ids: List[str]) -> None:
6264
alert_ids_chunks = self._split_list_to_chunks(alert_ids)
63-
logger.info("Update sent alerts")
65+
click.echo(f"Update sent alerts ({len(alert_ids)})")
6466
for alert_ids_chunk in alert_ids_chunks:
6567
self.dbt_runner.run(
6668
select="elementary_cli.update_alerts.update_sent_alerts",

elementary/utils/log.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ def format(self, record):
3030
ROTATION_BACKUP_COUNT = 4
3131

3232

33-
def get_console_handler():
33+
def get_console_handler(quiet_logs: bool = False):
3434
console_handler = logging.StreamHandler(sys.stdout)
3535
console_handler.setFormatter(FORMATTER)
36-
console_handler.setLevel(logging.DEBUG if is_debug() else logging.INFO)
36+
if is_debug():
37+
console_handler.setLevel(logging.DEBUG)
38+
elif quiet_logs:
39+
console_handler.setLevel(logging.WARNING)
40+
else:
41+
console_handler.setLevel(logging.INFO)
3742
return console_handler
3843

3944

@@ -55,7 +60,14 @@ def get_logger(logger_name):
5560
return logger
5661

5762

58-
def set_root_logger_handlers(logger_name, files_target_path):
63+
def set_root_logger_handlers(logger_name, files_target_path, quiet_logs: bool = False):
5964
logger = logging.getLogger(logger_name)
60-
logger.addHandler(get_console_handler())
65+
66+
# Disable propagation to root logger to avoid duplicate logs
67+
logger.propagate = False
68+
69+
logger.addHandler(get_console_handler(quiet_logs=quiet_logs))
6170
logger.addHandler(get_file_handler(files_target_path))
71+
72+
# Set logger level to DEBUG so it doesn't filter messages (handler will filter)
73+
logger.setLevel(logging.DEBUG)

0 commit comments

Comments
 (0)