thinlog.handlers.json_http module#
Handler that sends JSON log records via HTTP POST.
- class thinlog.handlers.json_http.JsonHTTPHandler(settings: JsonHttpHandlerSettings | dict[str, Any])[source]#
Bases:
HandlerSend formatted log records as JSON via HTTP POST using
httpx.The HTTP client is lazily initialised on first use. Per-record overrides (URL, headers, disable) can be provided via a
handlers_context.json_httpdict on the log record.- Parameters:
settings – A
JsonHttpHandlerSettingsor a dict of its fields.
- property client: Client#
Lazily initialised
httpx.Client.
- emit(record: LogRecord) None[source]#
Format and POST the record as JSON.
Supports per-record overrides via
record.handlers_context["json_http"]:disable– skip this record entirely.url– override the target URL.headers– replace the default headers.append_headers– merge additional headers.
- class thinlog.handlers.json_http.JsonHttpHandlerSettings(url: str, headers: dict[str, str], level: str | int = 0, timeout: int = 5, proxy: str | None = None)[source]#
Bases:
objectSettings for
JsonHTTPHandler.The first instance created is stored as a global singleton accessible via
global_instance().- Parameters:
url – Target URL for HTTP POST requests.
headers – Default HTTP headers sent with every request.
level – Minimum log level (name or int).
timeout – HTTP request timeout in seconds.
proxy – Optional HTTP proxy URL.
- classmethod global_instance() JsonHttpHandlerSettings | None[source]#
Return the first-created settings instance, or
None.
- headers: dict[str, str]#
- level: str | int = 0#
- proxy: str | None = None#
- timeout: int = 5#
- url: str#