<@ULVA73B9P> How can I get rid of HTTP GET and POS...
# ask-marvin
m
@Marvin How can I get rid of HTTP GET and POST log messages to not be included in the logs? They look like this: INFO | httpx - HTTP Request: POST https://api.prefect.cloud/api/....
m
To disable HTTP logs in Prefect, you can adjust the logging configuration. Prefect uses Python's built-in logging module, and you can customize it to suit your needs. Here's an example of how you can disable HTTP logs:
Copy code
import logging
logging.getLogger("httpx").setLevel(logging.WARNING)
In this code, we're getting the logger for
httpx
(which is the library Prefect uses for HTTP requests) and setting its level to
WARNING
. This means that only warnings and errors will be logged, and informational messages (like the ones you're seeing) will be ignored. You can put this code at the top of your script, before any tasks or flows are defined, and it should apply to the entire application. Remember to be careful when adjusting logging levels, as it can make it harder to debug issues if you're not seeing all the logs.
m
@Marvin Can it be done in the logging.yaml file instead?
m
Yes, you can configure the logging level of
httpx
in the
logging.yaml
file as well. Here's how you can do it:
Copy code
yaml
version: 1
disable_existing_loggers: False
handlers:
  console:
    class: logging.StreamHandler
    formatter: simple
    stream: <ext://sys.stdout>
formatters:
  simple:
    format: '%(asctime)s | %(name)s | %(levelname)s: %(message)s'
root:
  level: INFO
  handlers: [console]
loggers:
  httpx:
    level: WARNING
    handlers: [console]
    propagate: no
In this configuration, we've added a new logger for
httpx
and set its level to
WARNING
. This means that only warnings and errors from
httpx
will be logged to the console. The
propagate: no
line means that these messages won't be passed to the root logger, so they won't be logged twice. You can adjust the
level
line to change the logging level for
httpx
. The available levels are
DEBUG
,
INFO
,
WARNING
,
ERROR
, and
CRITICAL
, in increasing order of severity. Remember to replace the existing
logging.yaml
file with this configuration, or merge it if you have other custom settings.
Yes, you can configure the logging level for
httpx
in the
logging.yaml
file as well. Here's how you can do it:
Copy code
yaml
version: 1
disable_existing_loggers: False
handlers:
  console:
    class: logging.StreamHandler
    formatter: basic
formatters:
  basic:
    format: "%(asctime)s | %(name)s | %(levelname)s: %(message)s"
loggers:
  httpx:
    level: WARNING
    handlers:
      - console
    propagate: False
root:
  level: INFO
  handlers:
    - console
In this configuration, we're setting the log level for
httpx
to
WARNING
, just like in the Python code. This means that only warnings and errors from
httpx
will be logged. You can adjust the
level
for other loggers in the same way. If you want to change the log level for the entire application, you can do so by changing the
level
under
root
.