Andreas Nord
11/02/2023, 10:16 AMAndreas Nord
11/02/2023, 10:17 AMMarvin
11/02/2023, 10:17 AMAndreas Nord
11/02/2023, 10:18 AMMarvin
11/02/2023, 10:18 AMMarvin
11/02/2023, 10:19 AMlogging.yml
with custom settings. You can specify the path to this file with PREFECT_LOGGING_SETTINGS_PATH
. If the file does not exist at the specified location, Prefect ignores the setting and uses the default configuration.
To access the Prefect logger, you can import it using from prefect import get_run_logger
. You can send messages to the logger in both flows and tasks. To log from a flow, retrieve a logger instance with get_run_logger()
, then call the standard Python logging methods.
Here is an example:
from prefect import flow, get_run_logger
@flow(name="log-example-flow")
def logger_flow():
logger = get_run_logger()
<http://logger.info|logger.info>("INFO level log message.")
Prefect automatically uses the flow run logger based on the flow context. If you run the above code, Prefect captures the following as a log event.
15:35:17.304 | INFO | Flow run 'mottled-marten' - INFO level log message.
The default flow run log formatter uses the flow run name for log messages.
Starting in 2.7.11, if you use a logger that sends logs to the API outside of a flow or task run, a warning will be shown. You may need to change the log level used by loggers from other libraries to see their log records.
You can override any logging configuration by setting an environment variable or Prefect configuration value.
For more information, you can refer to the Prefect logging guide.Jack P
11/02/2023, 2:46 PMPREFECT_LOGGING_EXTRA_LOGGERS
setting^Andreas Nord
11/02/2023, 3:34 PMPREFECT_LOGGING_EXTRA_LOGGERS=dbt
Does not work for meNate
11/02/2023, 3:50 PMPREFECT_LOGGING_EXTRA_LOGGERS
that should be what you want, how are you trying to use it? here's an example that works for me
the thing you pass should be the moduleAndreas Nord
11/02/2023, 4:01 PMimport os
from prefect import flow
from dbt.cli.main import dbtRunner
@flow
def run_dbt():
print(os.getenv("PREFECT_LOGGING_EXTRA_LOGGERS"))
dbt_run = dbtRunner().invoke(["run"])
if __name__ == "__main__":
run_dbt()
And the relevant part of the log (as you can see the last log message is not part of prefect logs):
dbt
16:57:47.044 | DEBUG | Flow run 'big-tench' - Executing flow 'run-dbt' for flow run 'big-tench'...
16:57:47.045 | DEBUG | Flow run 'big-tench' - Beginning execution...
15:57:47 Running with dbt=1.6.6