Logging#
In addition to existing success and failure messages in the terminal, IndexNow for Python can log HTTP request results and endpoint fallbacks to your application's logging system. Configure Python's standard logging module to choose which messages to display and where they go. These logs can help with debugging and monitoring submissions.
Configuration#
To see informational messages and warnings from this package only, attach a handler to the index_now logger before calling a submission method:
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
How it works:
- The
setLevelcontrols which messages pass through. - The
handlercontrols where they go and how they are formatted. - The
propagatesetting prevents these messages from also reaching handlers on the root logger.
These examples configure only the index_now logger. Logs from other libraries, for example urllib3 or other packages, follow your application's logging configuration.
Logging Suppressed by Default
If your application has not configured logging, the package suppresses its log output by default. The handler above receives only index_now records.
Set the Log Level#
Set the logger to logging.DEBUG to include details about each request and endpoint attempt:
| Python | |
|---|---|
4 | |
Sending Logs to a File#
To send package logs to a file, replace the StreamHandler with a FileHandler:
| Python | |
|---|---|
6 | |
Example Log Output#
For a successful submission to the default endpoint with no retries, the log output at INFO level is:
INFO index_now.submit.fallback: Submission accepted with HTTP status 200 on endpoint https://api.indexnow.org/indexnow
At DEBUG level, the same submission includes request and endpoint details:
DEBUG index_now.submit.fallback: Trying endpoint 1 of 1: https://api.indexnow.org/indexnow
DEBUG index_now.utility.http_client: Sending GET request (configured retries: 0)
DEBUG index_now.utility.http_client: GET request completed with HTTP status 200
INFO index_now.submit.fallback: Submission accepted with HTTP status 200 on endpoint https://api.indexnow.org/indexnow
The examples show only log records. Each submission also prints the package's existing terminal messages.
What Is Logged?#
| Type | Details |
|---|---|
| Logged | HTTP methods, retry counts, and response status codes Exception types Fallback activity and endpoint locations Sitemap locations, nested sitemap URLs for failed HTTP requests, filter settings, and URL counts when relevant |
| Not logged | By this package: request payloads, API keys sent with requests, submitted URLs, and sitemap contents Exception messages or response bodies |
Avoid Sensitive Information in Input Values
Some log messages include sitemap locations, filter settings, and fallback endpoints as supplied. When a nested sitemap request from a sitemap index returns an HTTP error, the log includes that nested sitemap URL. The package logs only the exception type for connection errors and timeouts. Do not include credentials or other sensitive information in these values or in URLs referenced by sitemap indexes. For example, avoid passing URLs like these:
https://example.com/sitemap.xml?api_key=SECRET_KEY
https://example.com/login?username=USER&password=PASSWORD