Skip to content

Commit 247a399

Browse files
committed
feat(logging): add structured log schema
1 parent b9faeb9 commit 247a399

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

docs/log.schema.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Log Schema for HTTP Cache
2+
3+
This document describes the structured log schema, in JSON format, used by the HTTP cache service. The schema is designed to provide detailed, machine-readable logs for cache operations, including hits, misses, stale responses, revalidations, bypasses, and errors.
4+
5+
| Field | Type | Description |
6+
| --------- | ------ | ----------------------------------------------------------------- |
7+
| timestamp | string | ISO8601 timestamp of the log entry |
8+
| level | string | Log level: `DEBUG`, `INFO`, `WARN`, `ERROR` |
9+
| service | string | Always `httpcache` |
10+
| event | string | Event type: `HIT`, `MISS`, etc. |
11+
| msg | string | Human-readable summary |
12+
| trace_id | string | Trace/correlation ID (if provided) |
13+
| error | string | Error message (only for error logs) |
14+
| request | object | HTTP request context (see [below](#request-object)) |
15+
| cache | object | Cache context (see [below](#cache-object)) |
16+
| misc | object | Additional context (optional, see [below](#misc-object-optional)) |
17+
18+
## `request` object
19+
| Field | Type | Description |
20+
| ------ | ------ | ---------------- |
21+
| method | string | HTTP method |
22+
| url | string | Full request URL |
23+
| host | string | Host header |
24+
25+
## `cache` object
26+
| Field | Type | Description |
27+
| ------- | ------ | ------------------- |
28+
| status | string | HIT, MISS, STALE... |
29+
| url_key | string | Cache key |
30+
31+
## `misc` object (optional)
32+
| Field | Type | Description |
33+
| ----------- | ------ | -------------------------------------------------------------- |
34+
| cc_request | object | Cache-Control request directives (if present) |
35+
| cc_response | object | Cache-Control response directives (if present) |
36+
| stored | object | Cached response details (if present) |
37+
| freshness | object | Freshness details (if present, see [below](#freshness-object)) |
38+
| ref | object | Reference details (if present) |
39+
40+
## `freshness` object (optional)
41+
| Field | Type | Description |
42+
| --------- | ------- | ----------------------------------------------------- |
43+
| is_stale | boolean | Whether the response is stale |
44+
| age | object | Age of the cached response (see [below](#age-object)) |
45+
| timestamp | string | Timestamp of the age calculation (ISO8601) |
46+
47+
## `age` object (optional)
48+
| Field | Type | Description |
49+
| --------- | ------ | ------------------------------------------ |
50+
| value | number | Age in seconds |
51+
| timestamp | string | Timestamp of the age calculation (ISO8601) |
52+
53+
54+
### Example
55+
```json
56+
{
57+
"timestamp": "2025-07-01T14:20:00.000Z",
58+
"level": "INFO",
59+
"service": "httpcache",
60+
"event": "HIT",
61+
"msg": "Cache hit; served from cache.",
62+
"trace_id": "abc123def456",
63+
"request": {
64+
"method": "GET",
65+
"url": "https://api.example.com/data",
66+
"host": "api.example.com"
67+
},
68+
"cache": {
69+
"status": "HIT",
70+
"url_key": "https://api.example.com/data"
71+
},
72+
"misc": {
73+
"cc_request": {"max-age":"60"},
74+
"cc_response": {"max-age":"120", "stale-while-revalidate":"30"},
75+
"freshness": {
76+
"is_stale":false,
77+
"age": {
78+
"value":298741541,
79+
"timestamp":"2025-07-01T14:35:19.298742743Z"
80+
},
81+
}
82+
}
83+
```

0 commit comments

Comments
 (0)