Moe
11/21/2023, 10:45 PMMarvin
11/21/2023, 10:45 PMimport 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.Moe
11/21/2023, 10:46 PMMarvin
11/21/2023, 10:47 PMhttpx
in the logging.yaml
file as well. Here's how you can do it:
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.Marvin
11/21/2023, 10:47 PMhttpx
in the logging.yaml
file as well. Here's how you can do it:
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
.