Skip to main content

Logging and diagnostics

The SDK uses Python's standard logging package. It does not configure the root logger, call logging.basicConfig(), or install stream/file handlers. Your application controls where logs go; the SDK only emits records under the sasvi logger hierarchy.

Basic setup​

Configure handlers in your application, then enable the SDK package logger:

import logging
import sasvi

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s %(message)s",
)

sasvi.configure_logging("INFO")

You can also set the SDK package logger level when constructing a client:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
)

log_level is package-wide for the current Python process. It is not bound to one client instance. If a later client is constructed with log_level="WARNING", that changes the sasvi package logger level for SDK logs in the process.

HTTP summary logs​

Set log_http=True to emit request/response summaries from the SDK transport layer. This covers generated service calls, handwritten service calls that use generated clients, custom endpoint requests, and token-provider HTTP traffic.

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
)

HTTP summary logs include:

  • HTTP method
  • sanitized URL
  • service name when known
  • response status code
  • duration in milliseconds
  • retry/final outcome
  • retry attempt number
  • selected correlation/request headers returned by the server

By default, query strings and headers are not included.

Raw response bodies​

Raw bodies are never logged just because the log level is DEBUG. They require explicit opt-in:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_response_body=True,
log_http_body_limit=4096,
)

Use response body logging for short diagnostic sessions, not as a normal production setting. The SDK truncates logged bodies to log_http_body_limit characters and skips binary, multipart, and streaming payloads.

Request body logging is separate:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_request_body=True,
)

Auth token request bodies are redacted even when request body logging is enabled. For other request bodies, the SDK redacts known secret keys in JSON and application/x-www-form-urlencoded payloads and applies best-effort redaction for common key=value text bodies. Use request body logging for short diagnostic sessions because domain data can still be sensitive.

Query strings and headers​

Query strings are hidden by default. Enable them only when they are needed for debugging:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_query=True,
)

Headers are also hidden by default:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_headers=True,
)

Sensitive headers and query parameters are redacted when query/header logging is enabled. Built-in redaction covers common auth and session values such as:

  • Authorization
  • cookies and Set-Cookie
  • CSRF/XSRF headers
  • access tokens and refresh tokens
  • passwords
  • client secrets
  • authorization codes

You can extend the redaction lists:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_query=True,
log_http_headers=True,
log_http_redacted_headers=frozenset({"X-My-Secret"}),
log_http_redacted_query_params=frozenset({"tenantSecret"}),
)

Custom redaction lists extend the SDK defaults; they do not replace them.

Slow request logs​

Use log_slow_request_seconds to elevate slow HTTP responses to warning level:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_slow_request_seconds=2.0,
)

This keeps normal HTTP summaries at log_http_level while making slow requests visible to handlers that collect warnings.

Environment variables​

SVIClient.from_env() supports these logging variables:

  • SASVI_LOG_LEVEL
  • SASVI_LOG_HTTP
  • SASVI_LOG_HTTP_LEVEL
  • SASVI_LOG_HTTP_RESPONSE_BODY
  • SASVI_LOG_HTTP_BODY_LIMIT

Example:

export SASVI_LOG_LEVEL=DEBUG
export SASVI_LOG_HTTP=true
export SASVI_LOG_HTTP_RESPONSE_BODY=true
export SASVI_LOG_HTTP_BODY_LIMIT=4096

Then:

client = sasvi.SVIClient.from_env()

Structured log fields​

HTTP log records include standard logging extra fields for applications that use JSON formatters or log processors:

  • sasvi_http_service
  • sasvi_http_method
  • sasvi_http_url
  • sasvi_http_status_code
  • sasvi_http_duration_ms
  • sasvi_http_attempt
  • sasvi_http_outcome

These fields are additive; simple text logging still works normally.

For normal production observability:

logging.basicConfig(level=logging.INFO)

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="INFO",
log_http=True,
log_slow_request_seconds=2.0,
)

For short-lived API troubleshooting:

logging.basicConfig(level=logging.DEBUG)

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_response_body=True,
log_http_body_limit=4096,
)

For maximum diagnostics, including query strings and headers:

client = sasvi.SVIClient(
base_url="https://viya.example.test",
auth=auth,
log_level="DEBUG",
log_http=True,
log_http_query=True,
log_http_headers=True,
log_http_request_body=True,
log_http_response_body=True,
)

Use the maximum diagnostics pattern carefully. It is useful for local troubleshooting and support sessions, but it should not be left on broadly in production.

What is never logged intentionally​

The SDK avoids intentionally logging:

  • bearer tokens
  • refresh tokens
  • passwords
  • client secrets
  • authorization codes
  • cookies
  • CSRF/XSRF tokens
  • binary files and images
  • multipart upload bodies
  • streaming request or response bodies

When request body logging is enabled, known secret keys in JSON and form bodies are redacted before the SDK emits the log record.

If your application adds its own HTTPX hooks, custom log handlers, or exception rendering, review those separately. The SDK can redact the records it emits, but it cannot control logging performed outside the SDK.