(raw: string, lineNo: number)
| 100 | } |
| 101 | |
| 102 | export function parseLogLine(raw: string, lineNo: number): LogLine { |
| 103 | const m = LINE_RE.exec(raw); |
| 104 | if (m === null) { |
| 105 | return { lineNo, time: null, level: null, message: raw, fields: {}, raw }; |
| 106 | } |
| 107 | const time = m[1]!; |
| 108 | const level = m[2]!.toUpperCase(); |
| 109 | const rest = m[3]!; |
| 110 | |
| 111 | const fields: Record<string, string> = {}; |
| 112 | let message = rest; |
| 113 | const fieldStart = rest.search(FIELD_START_RE); |
| 114 | if (fieldStart >= 0) { |
| 115 | message = rest.slice(0, fieldStart).trim(); |
| 116 | const fieldsPart = rest.slice(fieldStart); |
| 117 | for (const fm of fieldsPart.matchAll(FIELD_RE)) { |
| 118 | fields[fm[1]!] = fm[2]!; |
| 119 | } |
| 120 | } |
| 121 | return { lineNo, time, level, message: message.trim(), fields, raw }; |
| 122 | } |
no test coverage detected