Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class LogFileManager {

#queryCount: number = 0;

#isPrettified: boolean = false;

/**
* Private constructor for LogFileManager. This is not intended to be invoked publicly.
* Instead, use LogFileManager.create() to create a new instance of the class.
Expand Down Expand Up @@ -194,6 +196,10 @@ class LogFileManager {
}
}

setIsPrettified (isPrettified: boolean) {
this.#isPrettified = isPrettified;
}

/**
* Exports a chunk of log events, sends the results to the renderer, and schedules the next
* chunk if more log events remain.
Expand Down Expand Up @@ -229,12 +235,11 @@ class LogFileManager {
* Loads a page of log events based on the provided cursor.
*
* @param cursor The cursor indicating the page to load. See {@link CursorType}.
* @param isPrettified Are the log messages pretty printed.
* @return An object containing the logs as a string, a map of line numbers to log event
* numbers, and the line number of the first line in the cursor identified event.
* @throws {Error} if any error occurs during decode.
*/
loadPage (cursor: CursorType, isPrettified: boolean): PageData {
loadPage (cursor: CursorType): PageData {
console.debug(`loadPage: cursor=${JSON.stringify(cursor)}`);
const filteredLogEventMap = this.#decoder.getFilteredLogEventMap();
const numActiveEvents: number = filteredLogEventMap ?
Expand Down Expand Up @@ -264,7 +269,7 @@ class LogFileManager {
const beginLineNumToLogEventNum: BeginLineNumToLogEventNumMap = new Map();
let currentLine = 1;
results.forEach(({message, logEventNum}) => {
const printedMsg = (isPrettified) ?
const printedMsg = (this.#isPrettified) ?
`${jsBeautify(message)}\n` :
message;

Expand Down
12 changes: 8 additions & 4 deletions src/services/LogFileManagerProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ class LogFileManagerProxy {
};
}

loadPage (cursor: CursorType, isPrettified: boolean): PageData {
loadPage (cursor: CursorType): PageData {
const logFileManager = this.#getLogFileManager();
return logFileManager.loadPage(cursor, isPrettified);
return logFileManager.loadPage(cursor);
}

setFilter (
cursor: CursorType,
isPrettified: boolean,
logLevelFilter: LogLevelFilter
): PageData {
const logFileManager = this.#getLogFileManager();
logFileManager.setLogLevelFilter(logLevelFilter);

return this.loadPage(cursor, isPrettified);
return this.loadPage(cursor);
}

setIsPrettified (isPrettified: boolean): void {
const logFileManager = this.#getLogFileManager();
logFileManager.setIsPrettified(isPrettified);
}

exportLogs (): void {
Expand Down
3 changes: 1 addition & 2 deletions src/stores/logFileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ const useLogFileStore = create<LogFileState>((set) => ({

set(fileInfo);

const {isPrettified} = useViewStore.getState();
const pageData = await logFileManagerProxy.loadPage(cursor, isPrettified);
const pageData = await logFileManagerProxy.loadPage(cursor);
updatePageData(pageData);
setUiState(UI_STATE.READY);

Expand Down
3 changes: 1 addition & 2 deletions src/stores/viewStore/createViewFilterSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ const createViewFilterSlice: StateCreator<
setUiState(UI_STATE.FAST_LOADING);
(async () => {
const {logFileManagerProxy} = useLogFileManagerStore.getState();
const {isPrettified, logEventNum} = get();
const {logEventNum} = get();
const pageData = await logFileManagerProxy.setFilter(
{
code: CURSOR_CODE.EVENT_NUM,
args: {
eventNum: logEventNum,
},
},
isPrettified,
filter
);

Expand Down
3 changes: 1 addition & 2 deletions src/stores/viewStore/createViewPageSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ const createViewPageSlice: StateCreator<

(async () => {
const {logFileManagerProxy} = useLogFileManagerStore.getState();
const {isPrettified} = get();
const pageData = await logFileManagerProxy.loadPage(cursor, isPrettified);
const pageData = await logFileManagerProxy.loadPage(cursor);
const {updatePageData} = get();
updatePageData(pageData);
setUiState(UI_STATE.READY);
Expand Down
15 changes: 8 additions & 7 deletions src/utils/url/urlHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ const getCursorFromHashParams = ({isPrettified, logEventNum, timestamp}: {
return null;
}

const {
isPrettified: prevIsPrettified, setIsPrettified, setLogEventNum,
} = useViewStore.getState();
const {isPrettified: prevIsPrettified, setLogEventNum} = useViewStore.getState();
const clampedLogEventNum = clamp(logEventNum, 1, numEvents);

if (isPrettified !== prevIsPrettified) {
setIsPrettified(isPrettified);

return {
code: CURSOR_CODE.EVENT_NUM,
args: {eventNum: clampedLogEventNum},
Expand Down Expand Up @@ -84,7 +80,7 @@ const getCursorFromHashParams = ({isPrettified, logEventNum, timestamp}: {
const updateViewHashParams = () => {
const {isPrettified, logEventNum, timestamp} = getWindowUrlHashParams();
updateWindowUrlHashParams({
isPrettified: URL_HASH_PARAMS_DEFAULT.isPrettified,
isPrettified: isPrettified,
timestamp: URL_HASH_PARAMS_DEFAULT.timestamp,
});

Expand All @@ -97,7 +93,12 @@ const updateViewHashParams = () => {
(async () => {
const {logFileManagerProxy} = useLogFileManagerProxyStore.getState();
const {updatePageData} = useViewStore.getState();
const pageData = await logFileManagerProxy.loadPage(cursor, isPrettified);
const {isPrettified: prevIsPrettified, setIsPrettified} = useViewStore.getState();
if (isPrettified !== prevIsPrettified) {
setIsPrettified(isPrettified);
await logFileManagerProxy.setIsPrettified(isPrettified);
}
const pageData = await logFileManagerProxy.loadPage(cursor);
updatePageData(pageData);
const {setUiState} = useUiStore.getState();
setUiState(UI_STATE.READY);
Expand Down
Loading