Skip to content

Commit 72acd7d

Browse files
authored
Reduce content logged in redux logger (microsoft#8729)
* Reduce content logged in redux logger * Oops
1 parent e4067e3 commit 72acd7d

File tree

1 file changed

+37
-2
lines changed
  • src/datascience-ui/interactive-common/redux

1 file changed

+37
-2
lines changed

src/datascience-ui/interactive-common/redux/store.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'use strict';
44
import * as fastDeepEqual from 'fast-deep-equal';
55
import * as Redux from 'redux';
6-
import { logger } from 'redux-logger';
6+
import { createLogger } from 'redux-logger';
77

88
import { Identifiers } from '../../../client/datascience/constants';
99
import { InteractiveWindowMessages } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
@@ -14,7 +14,7 @@ import { PostOffice } from '../../react-common/postOffice';
1414
import { combineReducers, createQueueableActionMiddleware, QueuableAction } from '../../react-common/reduxUtils';
1515
import { computeEditorOptions, loadDefaultSettings } from '../../react-common/settingsReactSide';
1616
import { createEditableCellVM, generateTestState } from '../mainState';
17-
import { AllowedMessages, createPostableAction, generatePostOfficeSendReducer } from './postOffice';
17+
import { AllowedMessages, createPostableAction, generatePostOfficeSendReducer, IncomingMessageActions } from './postOffice';
1818

1919
function generateDefaultState(skipDefault: boolean, testMode: boolean, baseTheme: string, editable: boolean): IMainState {
2020
const defaultSettings = loadDefaultSettings();
@@ -143,6 +143,41 @@ function createMiddleWare(testMode: boolean): Redux.Middleware<{}, IStore>[] {
143143
const testMiddleware = testMode ? createTestMiddleware() : undefined;
144144

145145
// Create the logger if we're not in production mode or we're forcing logging
146+
const reduceLogMessage = '<payload too large to displayed in logs (at least on CI)>';
147+
const actionsWithLargePayload = [IncomingMessageActions.LOADONIGASMASSEMBLYRESPONSE, IncomingMessageActions.GETCSSRESPONSE, IncomingMessageActions.LOADTMLANGUAGERESPONSE];
148+
const logger = createLogger({
149+
// tslint:disable-next-line: no-any
150+
stateTransformer: (state: any) => {
151+
if (!state || typeof state !== 'object'){
152+
return state;
153+
}
154+
// tslint:disable-next-line: no-any
155+
const rootState = {...state} as any;
156+
if ('main' in rootState && typeof rootState.main === 'object'){
157+
// tslint:disable-next-line: no-any
158+
const main = rootState.main = {...rootState.main} as any as Partial<IMainState>;
159+
main.rootCss = reduceLogMessage;
160+
main.rootStyle = reduceLogMessage;
161+
// tslint:disable-next-line: no-any
162+
main.editorOptions = reduceLogMessage as any;
163+
// tslint:disable-next-line: no-any
164+
main.settings = reduceLogMessage as any;
165+
}
166+
rootState.monaco = reduceLogMessage;
167+
168+
return rootState;
169+
},
170+
// tslint:disable-next-line: no-any
171+
actionTransformer: (action: any) => {
172+
if (!action){
173+
return action;
174+
}
175+
if (actionsWithLargePayload.indexOf(action.type) >= 0){
176+
return { ...action, payload: reduceLogMessage };
177+
}
178+
return action;
179+
}
180+
});
146181
const loggerMiddleware = process.env.VSC_PYTHON_FORCE_LOGGING !== undefined || (process.env.NODE_ENV !== 'production' && !testMode)
147182
? logger : undefined;
148183

0 commit comments

Comments
 (0)