<@ULVA73B9P> After adding an external logger using...
# ask-marvin
m
@Marvin After adding an external logger using
PREFECT_LOGGING_EXTRA_LOGGERS
, how do I display the source module and the linenumber of the external logger in the prefect UI?
m
To display the source module and line number of an external logger in the Prefect UI, you can configure the logging format used by Prefect. This involves setting up a custom logging configuration, often via a
logging.yml
file or directly in your code, to include the
%(module)s
and
%(lineno)d
format specifiers in the log format string. Here's a concise guide on how you might achieve this: 1. Custom Logging Configuration: You can provide a custom
logging.yml
file to Prefect. This file should define the format for logs to include the module and line number. An example format string could be:
Copy code
yaml
   format: '%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s'
2. Environment Variable: Use the
PREFECT_LOGGING_EXTRA_LOGGERS
environment variable to specify additional loggers you want to configure. This can be set in your environment or within your Prefect profile. 3. Logger Setup in Code: If you prefer a programmatic approach, you can configure the logger directly in your Python code using the
logging
module:
Copy code
python
   import logging

   logger = logging.getLogger('your_logger_name')
   handler = logging.StreamHandler()
   formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s')
   handler.setFormatter(formatter)
   logger.addHandler(handler)
For more detailed instructions on configuring logging in Prefect, you can refer to the Prefect Logging Documentation. It seems you prefer an imperative programming style, so configuring logging directly in your code might be more aligned with your preferences. If you need more help, feel free to ask!