<@ULVA73B9P> Is there a way to distinguish logs ge...
# ask-community
d
@Marvin Is there a way to distinguish logs generated by user code and by Prefect itself? Maybe it's possible to create custom log level?
m
Yes, you can distinguish logs generated by user code from those generated by Prefect itself by configuring logging settings. Prefect allows you to customize logging behavior using a
logging.yml
configuration file. You can specify different log levels and handlers for different parts of your application, including separating user logs from Prefect's internal logs. Here's a concise approach: 1. Custom Logging Configuration: You can create a custom
logging.yml
file and define different loggers for your user code and Prefect. Place this file in your
PREFECT_HOME
directory or specify its path using the
PREFECT_LOGGING_SETTINGS_PATH
environment variable. 2. Log Levels: Configure different log levels for different components. For example, you might want to set a higher verbosity for your user code and a lower one for Prefect logs. 3. Loggers and Handlers: Use different loggers and handlers for your user code and Prefect. Prefect's logging module includes various classes and functions to facilitate this, such as
get_run_logger
and
PrefectLogAdapter
. For more detailed instructions, you can refer to the Prefect logging documentation. If you need to implement a custom log level, you can do so by extending Python's logging capabilities, which Prefect's configuration supports.