Skip to content

Commit

Permalink
vdk-core: vdk run logging levels
Browse files Browse the repository at this point in the history
`vdk -v LEVEL` can be used to set logging level. But during vdk run this
was overriden by default levels set when configuring loggers. So `vdk -v
LEVEL` was not really working. This fixes that.

Logs of the vdk namespaces can also be controled by separate configu
LOG_LEVEL_VDK. It is set to INFO by default.

Testing Done: ran `vdk -v DEBUG run example-job` and `vdk run
example-job` and saw expected logs

Signed-off-by: Antoni Ivanov <[email protected]>
  • Loading branch information
antoniivanov committed Nov 6, 2021
1 parent c30aa6e commit bd69266
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion projects/vdk-core/cicd/example-job/30_check_orders_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
"""
import logging

log = logging.getLogger(__name__)


def run(job_input):
"""
This method is called automatically during execution. Only scripts containing this method are executed by VDK.
Arguments:
job_input: object automatically passed to run() method by VDK on execution.
"""
log.debug(f"Start data job step {__name__}.")
result = job_input.execute_query(
"""
select count(1) from orders
"""
)
if result and result[0][0] > 0:
logging.getLogger(__name__).info("Job has completed successfully")
log.info("Job has completed successfully")
else:
raise Exception("Job has failed. Could not get correct number of rows.")
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ def configure_loggers(
"requests_kerberos": {"level": "INFO"},
"requests_oauthlib": {"level": "INFO"},
"urllib3": {"level": "INFO"},
"taurus": {"level": vdk_logging_level},
"vdk": {"level": vdk_logging_level},
}

_FORMATTERS = {"detailedFormatter": {"format": DETAILED_FORMAT}}

_CONSOLE_HANDLER = {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "detailedFormatter",
"stream": "ext://sys.stderr",
}
Expand All @@ -65,7 +64,7 @@ def configure_loggers(
"version": 1,
"handlers": {"consoleHandler": _CONSOLE_HANDLER},
"formatters": _FORMATTERS,
"root": {"handlers": ["consoleHandler"], "level": "INFO"},
"root": {"handlers": ["consoleHandler"]},
"loggers": _LOGGERS,
"disable_existing_loggers": False,
}
Expand All @@ -77,7 +76,7 @@ def configure_loggers(
"version": 1,
"handlers": {"consoleHandler": _CONSOLE_HANDLER},
"formatters": _FORMATTERS,
"root": {"handlers": ("consoleHandler",), "level": "DEBUG"},
"root": {"handlers": ("consoleHandler",)},
"loggers": _LOGGERS,
"disable_existing_loggers": False,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def vdk_configure(self, config_builder: ConfigurationBuilder) -> None:
) # {LOCAL, CLOUD, NONE} To be overridden when executing in cloud
config_builder.add(
LOG_LEVEL_VDK,
"DEBUG",
"INFO",
"Logging verbosity of VDK code can be controlled from here. "
"Allowed values: CRITICAL, ERROR, WARNING, INFO, DEBUG",
)
Expand Down

0 comments on commit bd69266

Please sign in to comment.