ccproxy.core.plugins.hooks.implementations.formatters¶
ccproxy.core.plugins.hooks.implementations.formatters
¶
Core formatters for HTTP request/response logging.
These formatters are used by the core HTTP tracer hook and can be shared across different plugins that need HTTP logging capabilities.
JSONFormatter
¶
JSONFormatter(
log_dir="/tmp/ccproxy/traces",
verbose_api=True,
json_logs_enabled=True,
redact_sensitive=True,
truncate_body_preview=1024,
)
Formats requests/responses as structured JSON for observability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_dir
|
str
|
Directory for log files |
'/tmp/ccproxy/traces'
|
verbose_api
|
bool
|
Enable verbose API logging |
True
|
json_logs_enabled
|
bool
|
Enable JSON file logging |
True
|
redact_sensitive
|
bool
|
Redact sensitive headers |
True
|
truncate_body_preview
|
int
|
Max body preview size |
1024
|
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
from_config
classmethod
¶
Create JSONFormatter from a RequestTracerConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
RequestTracerConfig instance |
required |
Returns:
| Type | Description |
|---|---|
JSONFormatter
|
JSONFormatter instance |
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
redact_headers
staticmethod
¶
Redact sensitive headers for safe logging.
- Replaces authorization, x-api-key, cookie values with [REDACTED]
- Preserves header names for debugging
- Returns new dict without modifying original
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_request
async
¶
log_request(
request_id,
method,
url,
headers,
body,
request_type="provider",
context=None,
hook_type=None,
)
Log structured request data.
- Logs at TRACE level with redacted headers
- Writes to request log file with complete data (if configured)
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
log_response
async
¶
log_response(
request_id,
status,
headers,
body,
response_type="provider",
context=None,
hook_type=None,
)
Log structured response data.
- Logs at TRACE level
- Truncates body preview for console
- Handles binary data gracefully
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
log_stream_chunk
async
¶
Record individual stream chunk (optional, for deep debugging).
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_error
async
¶
Log error information.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_provider_request
async
¶
Log provider request.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_provider_response
async
¶
Log provider response.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_stream_start
async
¶
Log stream start.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
log_stream_complete
async
¶
log_stream_complete(
request_id,
provider=None,
total_chunks=None,
total_bytes=None,
usage_metrics=None,
)
Log stream completion with metrics.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/json.py
RawHTTPFormatter
¶
RawHTTPFormatter(
log_dir="/tmp/ccproxy/traces",
enabled=True,
log_client_request=True,
log_client_response=True,
log_provider_request=True,
log_provider_response=True,
max_body_size=10485760,
exclude_headers=None,
)
Formats and logs raw HTTP protocol data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_dir
|
str
|
Directory for raw HTTP log files |
'/tmp/ccproxy/traces'
|
enabled
|
bool
|
Enable raw HTTP logging |
True
|
log_client_request
|
bool
|
Log client requests |
True
|
log_client_response
|
bool
|
Log client responses |
True
|
log_provider_request
|
bool
|
Log provider requests |
True
|
log_provider_response
|
bool
|
Log provider responses |
True
|
max_body_size
|
int
|
Maximum body size to log |
10485760
|
exclude_headers
|
list[str] | None
|
Headers to redact |
None
|
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
from_config
classmethod
¶
Create RawHTTPFormatter from a RequestTracerConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
RequestTracerConfig instance |
required |
Returns:
| Type | Description |
|---|---|
RawHTTPFormatter
|
RawHTTPFormatter instance |
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
should_log
¶
log_client_request
async
¶
Log raw client request data.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
log_client_response
async
¶
Log raw client response data.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
log_provider_request
async
¶
Log raw provider request data.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
log_provider_response
async
¶
Log raw provider response data.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
build_raw_request
¶
Build raw HTTP/1.1 request format.
Source code in ccproxy/core/plugins/hooks/implementations/formatters/raw.py
build_raw_response
¶
Build raw HTTP/1.1 response headers.