Skip to content
2 changes: 1 addition & 1 deletion src/components/Editor/MonacoInstance/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const setupCustomLogLanguage = () => {
TOKEN_NAME.CUSTOM_FATAL,
],
[
/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})Z?/,
/\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}:\d{2}(?:[.,]\d+)?(?:[+-]\d{2}:?\d{2}|Z)?)?/,
TOKEN_NAME.CUSTOM_DATE,
],
[
Expand Down
32 changes: 30 additions & 2 deletions src/services/decoders/ClpIrDecoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ class ClpIrDecoder implements Decoder {
return new ClpIrDecoder(module, dataArray, decoderOptions);
}

/**
* Formats unstructured log events by prepending a formatted timestamp to each message.
*
* @param logEvents
* @return The formatted log events.
*/
static #formatUnstructuredResults = (logEvents: DecodeResult[]): DecodeResult[] => {
for (const r of logEvents) {
const [
message, timestamp,
] = r;

const dayJsTimestamp: Dayjs = convertToDayjsTimestamp(timestamp);
r[0] = dayJsTimestamp.format("YYYY-MM-DDTHH:mm:ss.SSSZ") + message;
}

return logEvents;
};

getEstimatedNumEvents (): number {
return this.#streamReader.getNumEventsBuffered();
}
Expand Down Expand Up @@ -109,6 +128,15 @@ class ClpIrDecoder implements Decoder {
return true;
}

/**
* See {@link Decoder.decodeRange}.
*
* @param beginIdx
* @param endIdx
* @param useFilter
* @return
* @throws {Error} if the formatter is not set for structured logs.
*/
decodeRange (
beginIdx: number,
endIdx: number,
Expand All @@ -127,10 +155,10 @@ class ClpIrDecoder implements Decoder {
if (this.#streamType === CLP_IR_STREAM_TYPE.STRUCTURED) {
// eslint-disable-next-line no-warning-comments
// TODO: Revisit when we allow displaying structured logs without a formatter.
console.error("Formatter is not set for structured logs.");
throw new Error("Formatter is not set for structured logs.");
}

return results;
return ClpIrDecoder.#formatUnstructuredResults(results);
}

for (const r of results) {
Expand Down