| 39 | }; |
| 40 | |
| 41 | const createLogEntry = ( |
| 42 | message: string, |
| 43 | level: LogLevel, |
| 44 | timestamp: Date, |
| 45 | ): LogEntry => { |
| 46 | const formatMatch = message.match(LOG_FORMAT_REGEX); |
| 47 | |
| 48 | let target = ''; |
| 49 | let remainder = message; |
| 50 | |
| 51 | if (formatMatch) { |
| 52 | target = formatMatch[1]; |
| 53 | remainder = formatMatch[2]; |
| 54 | } |
| 55 | |
| 56 | const scopeMatch = remainder.match(SCOPE_PREFIX_REGEX); |
| 57 | const scopeRaw = scopeMatch?.[1] ?? ''; |
| 58 | const content = scopeMatch?.[2] ?? remainder; |
| 59 | const isPlugin = scopeRaw.startsWith('plugin:'); |
| 60 | |
| 61 | return { |
| 62 | id: uuid(), |
| 63 | timestamp, |
| 64 | level, |
| 65 | target, |
| 66 | source: { |
| 67 | type: isPlugin ? 'plugin' : 'core', |
| 68 | scope: isPlugin ? scopeRaw.slice(7) : scopeRaw, |
| 69 | }, |
| 70 | message: content, |
| 71 | }; |
| 72 | }; |
| 73 | |
| 74 | const logBuffer = new RingBuffer<LogEntry>(MAX_LOG_ENTRIES); |
| 75 | let logStreamInitialized = false; |