Skip to content

Commit 5bc746a

Browse files
authored
new-log-viewer: Define interface for filtering by log level and add support (internally) to JsonlDecoder; Move timestamp field extraction from LogbackFormatter to JsonlDecoder. (#79)
1 parent b6b63ea commit 5bc746a

File tree

10 files changed

+437
-259
lines changed

10 files changed

+437
-259
lines changed

new-log-viewer/src/services/LogFileManager/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Decoder,
33
DecoderOptionsType,
4-
LOG_EVENT_FILE_END_IDX,
54
} from "../../typings/decoders";
65
import {MAX_V8_STRING_LENGTH} from "../../typings/js";
76
import {
@@ -52,10 +51,10 @@ class LogFileManager {
5251
this.#pageSize = pageSize;
5352
this.#decoder = decoder;
5453

55-
// Build index for the entire file
56-
const buildIdxResult = decoder.buildIdx(0, LOG_EVENT_FILE_END_IDX);
57-
if (null !== buildIdxResult && 0 < buildIdxResult.numInvalidEvents) {
58-
console.error("Invalid events found in decoder.buildIdx():", buildIdxResult);
54+
// Build index for the entire file.
55+
const buildResult = decoder.build();
56+
if (0 < buildResult.numInvalidEvents) {
57+
console.error("Invalid events found in decoder.build():", buildResult);
5958
}
6059

6160
this.#numEvents = decoder.getEstimatedNumEvents();
@@ -122,13 +121,11 @@ class LogFileManager {
122121
return decoder;
123122
}
124123

125-
/**
126-
* Sets options for the decoder.
127-
*
124+
/* Sets any formatter options that exist in the decoder's options.
128125
* @param options
129126
*/
130-
setDecoderOptions (options: DecoderOptionsType) {
131-
this.#decoder.setDecoderOptions(options);
127+
setFormatterOptions (options: DecoderOptionsType) {
128+
this.#decoder.setFormatterOptions(options);
132129
}
133130

134131
/**
@@ -144,9 +141,10 @@ class LogFileManager {
144141
logs: string,
145142
} {
146143
const endLogEventIdx = Math.min(beginLogEventIdx + EXPORT_LOGS_CHUNK_SIZE, this.#numEvents);
147-
const results = this.#decoder.decode(
144+
const results = this.#decoder.decodeRange(
148145
beginLogEventIdx,
149-
endLogEventIdx
146+
endLogEventIdx,
147+
false,
150148
);
151149

152150
if (null === results) {
@@ -185,7 +183,12 @@ class LogFileManager {
185183
matchingLogEventNum,
186184
} = this.#getCursorData(cursor);
187185

188-
const results = this.#decoder.decode(pageBeginLogEventNum - 1, pageEndLogEventNum - 1);
186+
const results = this.#decoder.decodeRange(
187+
pageBeginLogEventNum - 1,
188+
pageEndLogEventNum - 1,
189+
false
190+
);
191+
189192
if (null === results) {
190193
throw new Error("Error occurred during decoding. " +
191194
`pageBeginLogEventNum=${pageBeginLogEventNum}, ` +

new-log-viewer/src/services/MainWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ onmessage = async (ev: MessageEvent<MainWorkerReqMessage>) => {
5050
throw new Error("Log file manager hasn't been initialized");
5151
}
5252
if ("undefined" !== typeof args.decoderOptions) {
53-
LOG_FILE_MANAGER.setDecoderOptions(args.decoderOptions);
53+
LOG_FILE_MANAGER.setFormatterOptions(args.decoderOptions);
5454
}
5555

5656
let decodedEventIdx = 0;
@@ -85,7 +85,7 @@ onmessage = async (ev: MessageEvent<MainWorkerReqMessage>) => {
8585
throw new Error("Log file manager hasn't been initialized");
8686
}
8787
if ("undefined" !== typeof args.decoderOptions) {
88-
LOG_FILE_MANAGER.setDecoderOptions(args.decoderOptions);
88+
LOG_FILE_MANAGER.setFormatterOptions(args.decoderOptions);
8989
}
9090
postResp(
9191
WORKER_RESP_CODE.PAGE_DATA,

new-log-viewer/src/services/decoders/ClpIrDecoder.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import {Nullable} from "../../typings/common";
44
import {
55
Decoder,
66
DecodeResultType,
7+
FilteredLogEventMap,
8+
LOG_EVENT_FILE_END_IDX,
79
LogEventCount,
810
} from "../../typings/decoders";
11+
import {LogLevelFilter} from "../../typings/logs";
912

1013

1114
class ClpIrDecoder implements Decoder {
@@ -31,19 +34,42 @@ class ClpIrDecoder implements Decoder {
3134
return this.#streamReader.getNumEventsBuffered();
3235
}
3336

34-
buildIdx (beginIdx: number, endIdx: number): Nullable<LogEventCount> {
37+
// eslint-disable-next-line class-methods-use-this
38+
getFilteredLogEventMap (): FilteredLogEventMap {
39+
// eslint-disable-next-line no-warning-comments
40+
// TODO: Update this after log level filtering is implemented in clp-ffi-js
41+
console.error("Not implemented.");
42+
43+
return null;
44+
}
45+
46+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
47+
setLogLevelFilter (logLevelFilter: LogLevelFilter): boolean {
48+
// eslint-disable-next-line no-warning-comments
49+
// TODO: Update this after log level filtering is implemented in clp-ffi-js
50+
console.error("Not implemented.");
51+
52+
return false;
53+
}
54+
55+
build (): LogEventCount {
3556
return {
3657
numInvalidEvents: 0,
37-
numValidEvents: this.#streamReader.deserializeRange(beginIdx, endIdx),
58+
numValidEvents: this.#streamReader.deserializeRange(0, LOG_EVENT_FILE_END_IDX),
3859
};
3960
}
4061

4162
// eslint-disable-next-line class-methods-use-this
42-
setDecoderOptions (): boolean {
63+
setFormatterOptions (): boolean {
4364
return true;
4465
}
4566

46-
decode (beginIdx: number, endIdx: number): Nullable<DecodeResultType[]> {
67+
decodeRange (
68+
beginIdx: number,
69+
endIdx: number,
70+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
71+
useFilter: boolean
72+
): Nullable<DecodeResultType[]> {
4773
return this.#streamReader.decodeRange(beginIdx, endIdx);
4874
}
4975
}

new-log-viewer/src/services/decoders/JsonlDecoder.ts

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)