-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new-log-viewer: Finish support for filtering by log-level and associated refactoring. #89
Changes from 11 commits
9f002a8
f66481f
8edcbf6
275edc0
1accf00
75b5dec
4d79444
e6fc92f
5915bd1
a1983d5
e3b2b36
03f1670
e904a28
b112382
e7ad6eb
c13df92
2cc0803
04b2515
a420d7e
914a188
45c2e42
aec63d5
934c7c6
e4e4aee
26b0bf3
6528c56
e53a904
3016d14
93a46f9
807066b
d03da58
dd9c92e
a87a9fc
a4f7a0f
b1e26e2
ae97ab3
bdfd2e0
80ccfec
963cbd5
0808a7b
6551edf
217693a
6488bf8
edbf7e1
eb706d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,10 @@ | ||||||||||||||
import {Nullable} from "../../typings/common"; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import 'Nullable' The import 🧰 Tools🪛 GitHub Check: lint-check
|
||||||||||||||
import { | ||||||||||||||
Decoder, | ||||||||||||||
DecoderOptionsType, | ||||||||||||||
} from "../../typings/decoders"; | ||||||||||||||
import {MAX_V8_STRING_LENGTH} from "../../typings/js"; | ||||||||||||||
import {LogLevelFilter} from "../../typings/logs"; | ||||||||||||||
import { | ||||||||||||||
BeginLineNumToLogEventNumMap, | ||||||||||||||
CURSOR_CODE, | ||||||||||||||
|
@@ -17,6 +19,8 @@ import JsonlDecoder from "../decoders/JsonlDecoder"; | |||||||||||||
import { | ||||||||||||||
getEventNumCursorData, | ||||||||||||||
getLastEventCursorData, | ||||||||||||||
getMatchingLogEventNum, | ||||||||||||||
getNewNumPages, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused imports 'getMatchingLogEventNum' and 'getNewNumPages' The functions 🧰 Tools🪛 GitHub Check: lint-check
|
||||||||||||||
getPageNumCursorData, | ||||||||||||||
loadFile, | ||||||||||||||
} from "./utils"; | ||||||||||||||
|
@@ -128,6 +132,19 @@ class LogFileManager { | |||||||||||||
this.#decoder.setFormatterOptions(options); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Sets the log level filter. | ||||||||||||||
* | ||||||||||||||
* @param logLevelFilter | ||||||||||||||
* @throws {Error} If changing the log level filter couldn't be set. | ||||||||||||||
*/ | ||||||||||||||
setLogLevelFilter (logLevelFilter: LogLevelFilter) { | ||||||||||||||
const result: boolean = this.#decoder.setLogLevelFilter(logLevelFilter); | ||||||||||||||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
if (false === result) { | ||||||||||||||
throw new Error("Failed to set log level filter for current decoder."); | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing error message for clarity. When throwing an error due to a failure in setting the log level filter, including the attempted Apply this change to improve the error message: if (false === result) {
- throw new Error("Failed to set log level filter for current decoder.");
+ throw new Error(`Failed to set log level filter ${logLevelFilter} for current decoder.`);
} 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the rabbit on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @junhaoliao, glad to hear that! (^.^)/ |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Loads log events in the range | ||||||||||||||
* [`beginLogEventIdx`, `beginLogEventIdx + EXPORT_LOGS_CHUNK_SIZE`), or all remaining log | ||||||||||||||
|
@@ -174,25 +191,29 @@ class LogFileManager { | |||||||||||||
logEventNum: number | ||||||||||||||
logs: string, | ||||||||||||||
pageNum: number | ||||||||||||||
numPages: number | ||||||||||||||
} { | ||||||||||||||
console.debug(`loadPage: cursor=${JSON.stringify(cursor)}`); | ||||||||||||||
|
||||||||||||||
const { | ||||||||||||||
pageBeginLogEventNum, | ||||||||||||||
pageEndLogEventNum, | ||||||||||||||
matchingLogEventNum, | ||||||||||||||
pageBeginIdx, | ||||||||||||||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
pageEndIdx, | ||||||||||||||
matchingIdx, | ||||||||||||||
} = this.#getCursorData(cursor); | ||||||||||||||
|
||||||||||||||
const filteredLogEventMap = this.#decoder.getFilteredLogEventMap(); | ||||||||||||||
const useFilter: boolean = null !== filteredLogEventMap; | ||||||||||||||
|
||||||||||||||
const results = this.#decoder.decodeRange( | ||||||||||||||
pageBeginLogEventNum - 1, | ||||||||||||||
pageEndLogEventNum - 1, | ||||||||||||||
false | ||||||||||||||
pageBeginIdx, | ||||||||||||||
pageEndIdx, | ||||||||||||||
useFilter | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
if (null === results) { | ||||||||||||||
throw new Error("Error occurred during decoding. " + | ||||||||||||||
`pageBeginLogEventNum=${pageBeginLogEventNum}, ` + | ||||||||||||||
`pageEndLogEventNum=${pageEndLogEventNum}`); | ||||||||||||||
`pageBeginIdx=${pageBeginIdx}, ` + | ||||||||||||||
`pageEndIdx=${pageEndIdx}`); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
const messages: string[] = []; | ||||||||||||||
|
@@ -211,13 +232,20 @@ class LogFileManager { | |||||||||||||
currentLine += msg.split("\n").length - 1; | ||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
const newPageNum: number = getChunkNum(pageBeginLogEventNum, this.#pageSize); | ||||||||||||||
const matchingLogEventNum = getMatchingLogEventNum(matchingIdx, filteredLogEventMap); | ||||||||||||||
const newPageNum: number = getChunkNum(pageBeginIdx + 1, this.#pageSize); | ||||||||||||||
const newNumPages: number = getNewNumPages( | ||||||||||||||
this.#numEvents, | ||||||||||||||
this.#pageSize, | ||||||||||||||
filteredLogEventMap, | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
return { | ||||||||||||||
beginLineNumToLogEventNum: beginLineNumToLogEventNum, | ||||||||||||||
cursorLineNum: 1, | ||||||||||||||
logEventNum: matchingLogEventNum, | ||||||||||||||
logs: messages.join(""), | ||||||||||||||
numPages: newNumPages, | ||||||||||||||
pageNum: newPageNum, | ||||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
|
@@ -226,39 +254,42 @@ class LogFileManager { | |||||||||||||
* Gets the data that corresponds to the cursor. | ||||||||||||||
* | ||||||||||||||
* @param cursor | ||||||||||||||
* @return Log event numbers for: | ||||||||||||||
* @return Index for: | ||||||||||||||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
* - the range [begin, end) of the page containing the matching log event. | ||||||||||||||
* - the log event number that matches the cursor. | ||||||||||||||
* @throws {Error} if the type of cursor is not supported. | ||||||||||||||
*/ | ||||||||||||||
#getCursorData (cursor: CursorType): { | ||||||||||||||
pageBeginLogEventNum: number, | ||||||||||||||
pageEndLogEventNum: number, | ||||||||||||||
matchingLogEventNum: number | ||||||||||||||
pageBeginIdx: number, | ||||||||||||||
pageEndIdx: number, | ||||||||||||||
matchingIdx: Nullable<number> | ||||||||||||||
} { | ||||||||||||||
const {code, args} = cursor; | ||||||||||||||
const filteredLogEventMap = this.#decoder.getFilteredLogEventMap(); | ||||||||||||||
const numEvents: number = filteredLogEventMap ? | ||||||||||||||
filteredLogEventMap.length : | ||||||||||||||
this.#numEvents; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay to do this. shall we rename in front-end as well? In front-end, it is always the total. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sounds like a good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now I just changed to activeNumEvents in this function. There are many many instances of numEvents in the code. |
||||||||||||||
|
||||||||||||||
if (0 === numEvents) { | ||||||||||||||
return {pageBeginIdx: 0, pageEndIdx: 0, matchingIdx: null}; | ||||||||||||||
} | ||||||||||||||
switch (code) { | ||||||||||||||
case CURSOR_CODE.PAGE_NUM: | ||||||||||||||
return getPageNumCursorData( | ||||||||||||||
args.pageNum, | ||||||||||||||
args.eventPositionOnPage, | ||||||||||||||
this.#numEvents, | ||||||||||||||
this.#pageSize | ||||||||||||||
numEvents, | ||||||||||||||
this.#pageSize, | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
case CURSOR_CODE.LAST_EVENT: | ||||||||||||||
return getLastEventCursorData( | ||||||||||||||
this.#numEvents, | ||||||||||||||
this.#pageSize | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
return getLastEventCursorData(numEvents, this.#pageSize); | ||||||||||||||
case CURSOR_CODE.EVENT_NUM: | ||||||||||||||
return getEventNumCursorData( | ||||||||||||||
args.eventNum, | ||||||||||||||
this.#numEvents, | ||||||||||||||
this.#pageSize | ||||||||||||||
numEvents, | ||||||||||||||
this.#pageSize, | ||||||||||||||
filteredLogEventMap, | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
default: | ||||||||||||||
throw new Error(`Unsupported cursor type: ${code}`); | ||||||||||||||
} | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we group these with the other useEffects?