log refactor

This commit is contained in:
2026-05-12 19:30:15 +03:00
parent 1d59df2233
commit b17b5333c7
84 changed files with 5827 additions and 3908 deletions

View File

@@ -37,7 +37,7 @@ Every log record MUST be a JSON object **on a single line** with the following k
| Field | Required | Type | Description |
|-------|----------|------|-------------|
| `ts` | yes | string | ISO-8601 timestamp with microseconds |
| `ts` | yes | string | ISO-8601 timestamp with millisecond precision |
| `level` | yes | string | Standard log level (`INFO`, `DEBUG`, `WARNING`, `ERROR`) |
| `trace_id` | yes | string | UUID of the incoming HTTP request or background job |
| `span_id` | no | string | UUID of the current function/block scope (optional) |
@@ -45,7 +45,7 @@ Every log record MUST be a JSON object **on a single line** with the following k
| `marker` | yes | string | One of `REASON`, `REFLECT`, `EXPLORE` (see below) |
| `intent` | yes | string | Human-readable one-line description of what this step intends to do/verify |
| `payload` | no | object | Arbitrary key-value data relevant to the step (params, result snippet) |
| `error` | no | string | Error message or reason, **only** for `EXPLORE` markers when a fallback is taken |
| `error` | conditional | string | Error message or reason. **Optional** for `REASON`/`REFLECT`, **required** for `EXPLORE` markers when a fallback or violation is taken |
### Example
@@ -213,6 +213,7 @@ class TraceMiddleware(BaseHTTPMiddleware):
For C4/C5 functions, a decorator that auto-emits REASON / REFLECT markers:
```python
import asyncio
from functools import wraps
def cot_span(marker: str = "REASON", intent: str | None = None):
@@ -299,6 +300,7 @@ export function log(src, marker, intent, payload, error) {
```svelte
<script>
import { log } from "$lib/cot-logger";
import { fetchApi } from "$lib/api";
import { page } from "$app/stores";
let { jobId } = $props();
@@ -307,7 +309,7 @@ async function loadJob() {
log("JobDetail.loadJob", "REASON", "Fetch job details", { jobId });
try {
const resp = await fetch(`/api/jobs/${jobId}`);
const resp = await fetchApi(`/api/jobs/${jobId}`);
if (!resp.ok) throw new Error(`Status ${resp.status}`);
const data = await resp.json();