| 11 | this.service = service; |
| 12 | } |
| 13 | emit(entry) { |
| 14 | // SmallCode: only emit logs when explicitly enabled. Otherwise stays silent |
| 15 | // to avoid polluting CLI output. Set SMALLCODE_COGNITION_LOG=stdout to enable |
| 16 | // structured logs to stdout, or SMALLCODE_COGNITION_LOG=stderr for stderr. |
| 17 | const target = process.env.SMALLCODE_COGNITION_LOG; |
| 18 | if (!target) |
| 19 | return; |
| 20 | const full = { |
| 21 | timestamp: new Date().toISOString(), |
| 22 | service: this.service, |
| 23 | span_id: (0, crypto_1.randomUUID)(), |
| 24 | ...entry, |
| 25 | }; |
| 26 | const fn = target === "stderr" ? console.error : |
| 27 | (entry.level === "error" || entry.level === "fatal" ? console.error : console.log); |
| 28 | fn(JSON.stringify(full)); |
| 29 | } |
| 30 | info(event, fields = {}) { |
| 31 | this.emit({ level: "info", event, status: "success", trace_id: fields.trace_id || "", ...fields }); |
| 32 | } |