Skip to content

Commit bae4848

Browse files
committed
feat: fine tune logs
1 parent 7251a20 commit bae4848

16 files changed

Lines changed: 121 additions & 30 deletions

app/actions/application.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import AbortionSystem, {
2222
ABORTION_ERROR,
2323
ABORTION_MANUAL
2424
} from '../utils/abortionSystem';
25+
import { logger } from '../utils/tracer-logger.js';
2526

2627
export const endApplicationProcess =
2728
(): ThunkAction => async (dispatch: Dispatch) => {
29+
logger.info('End application process...');
2830
dispatch(returnToSearchPage());
2931
dispatch(setBotMessage(null));
3032
dispatch(taskFinished());

app/actions/bot.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { electronRouting, setBrowserViewReady } from './electron';
3030
import type { LoginData } from '../reducers/configuration';
3131
import { LoginStatus } from '../reducers/configuration';
3232
import { setConfiguration } from './configuration';
33+
import { logger } from '../utils/tracer-logger.js';
3334

3435
export function queueInvestigateFlat(flatId: string): ThunkAction {
3536
return async (dispatch: Dispatch, getState: GetState) => {
@@ -85,6 +86,7 @@ export function setShowOverlay(showOverlay: boolean): Action {
8586
}
8687
export const navigateToFlatPage =
8788
(flatId: string) => async (dispatch: Dispatch) => {
89+
logger.trace('navigateToFlatPage');
8890
await sleep(10000);
8991
dispatch(setBotIsActing(true));
9092
dispatch(setBotMessage(`Wohnung ${flatId} suchen...`));
@@ -103,6 +105,7 @@ export const navigateToFlatPage =
103105
/* eslint-disable no-await-in-loop */
104106
while (AbortionSystem.nestedFunctionsMayContinue) {
105107
if (!(await puppetView.elementExists(flatTitleSelector))) {
108+
// now the absence of the element signals the success - we're on the next page
106109
return true;
107110
}
108111

@@ -127,6 +130,7 @@ export function taskFinished(): Action {
127130
}
128131
export function returnToSearchPage(forceReload: boolean = false) {
129132
return async (dispatch: Dispatch, getState: GetState) => {
133+
logger.trace(`returnToSearchPage force:${forceReload}`);
130134
const { electron, configuration } = getState();
131135

132136
if (electron.views.puppet.url === configuration.searchUrl && !forceReload) {

app/flat/assessment.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '../utils/tracer-logger.js';
12
import type { Configuration } from '../reducers/configuration';
23
import { getConfigurationFilterHash } from '../reducers/configuration';
34
import type { FlatData, OverviewDataEntry, Verdict } from '../reducers/data';
@@ -9,6 +10,10 @@ export function assessFlat(
910
overviewDataEntry: OverviewDataEntry,
1011
flatData?: FlatData
1112
): Verdict {
13+
logger.trace();
14+
// logger.log("configuration:", configuration);
15+
logger.log('overviewDataEntry:', overviewDataEntry);
16+
logger.log('flatData:', flatData);
1217
let action: FlatAction = FlatAction.IGNORE;
1318
const reasons = [];
1419

@@ -190,6 +195,8 @@ export function assessFlat(
190195
}
191196
}
192197

198+
logger.debug(`Have verdict ${action} [scope=${scope}]`);
199+
193200
return {
194201
flatId: overviewDataEntry.id,
195202
configurationHash: getConfigurationFilterHash(configuration),

app/main.dev.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const isProduction = process.env.NODE_ENV === 'production';
2222
const isDevelopment = process.env.NODE_ENV === 'development';
2323
const enableDebug = process.env.ENABLE_DEBUG === 'true';
2424
const enableDevtools = isDevelopment || enableDebug;
25+
logger.info(
26+
`ENVIRONMENT prod:${isProduction} dev:${isDevelopment} debug:${enableDebug} tools:${enableDevtools}`
27+
);
2528

2629
let isLaunching = true;
2730

@@ -67,6 +70,7 @@ const appOnReady = async (store) => {
6770
}
6871

6972
/* Initialize views... */
73+
logger.info('Initialize views...');
7074

7175
mainWindow = new BrowserWindow({
7276
show: false,
@@ -82,7 +86,9 @@ const appOnReady = async (store) => {
8286
options: WebPreferences,
8387
initialUrl: string
8488
): WebContentsView => {
85-
logger.trace('args : %s %j %s', name, options, initialUrl);
89+
logger.trace(`name:${name}`);
90+
logger.log(`initialUrl:${initialUrl}`);
91+
logger.log('options:', options);
8692
if (mainWindow === undefined || mainWindow === null) {
8793
throw Error('Main window not defined!');
8894
}
@@ -169,6 +175,7 @@ const appOnReady = async (store) => {
169175
}
170176

171177
/* Add event listeners... */
178+
logger.info('Add event listeners...');
172179

173180
const configurationViewDidFinishLoad = async () => {
174181
logger.trace();
@@ -203,6 +210,7 @@ const appOnReady = async (store) => {
203210
mainWindow.on('closed', () => mainWindowOnClosed());
204211
mainWindow.setMenuBarVisibility(false);
205212

213+
logger.info('Initialize AppUpdater...');
206214
AppUpdater.init();
207215
AppUpdater.onUpdateAvailable((version) => {
208216
store.dispatch(setAvailableVersion(version));
@@ -215,6 +223,7 @@ const appOnReady = async (store) => {
215223
AppUpdater.onDownloadProgress((percentage) => {
216224
store.dispatch(setUpdateDownloadProgress(percentage));
217225
});
226+
logger.trace('DONE');
218227
};
219228

220229
const configureStoreThen = async (store) => {

app/middleware/bot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
URL_PARAMETER_SORT_NEWEST
3030
} from '../constants/urls';
3131
import { CAPTCHA_HINT } from '../constants/documentTitles';
32+
import { logger } from '../utils/tracer-logger.js';
3233

3334
export default (store: Store & { dispatch: Dispatch }) =>
3435
(next: (action: Action) => void) =>
@@ -83,6 +84,7 @@ export default (store: Store & { dispatch: Dispatch }) =>
8384
}
8485

8586
if (puppet.url.startsWith(URL_SEARCH_PAGE)) {
87+
logger.info('Finished loading search page...');
8688
const {
8789
configuration: { experimentalFeatures }
8890
} = store.getState();
@@ -120,6 +122,7 @@ export default (store: Store & { dispatch: Dispatch }) =>
120122
}
121123

122124
if (puppet.url.startsWith(URL_PREFIX_FLAT_LISTING)) {
125+
logger.info('Finished loading flat expose page...');
123126
await store.dispatch(getFlatData());
124127
store.dispatch(refreshVerdicts());
125128
}
@@ -149,20 +152,24 @@ export default (store: Store & { dispatch: Dispatch }) =>
149152
// eslint-disable-next-line default-case
150153
switch (verdict.action) {
151154
case FlatAction.NOTIFY_VIEWING_DATE:
155+
logger.info(`Notify me for flat ${flatId}...`);
152156
store.dispatch(
153157
sendFlatViewingNotificationMail(contactData, flatOverview)
154158
);
155159
break;
156160

157161
case FlatAction.INVESTIGATE:
162+
logger.info(`Schedule flat ${flatId} for investigation`);
158163
store.dispatch(queueInvestigateFlat(flatId));
159164
break;
160165

161166
case FlatAction.APPLY:
167+
logger.info(`Applying for flat ${flatId}...`);
162168
store.dispatch(generateApplicationTextAndSubmit(flatId));
163169
break;
164170

165171
case FlatAction.DISCARD:
172+
logger.info(`Discard flat ${flatId}`);
166173
store.dispatch(discardApplicationProcess(flatOverview));
167174
break;
168175
}

app/middleware/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '../utils/tracer-logger.js';
12
import { setSearchUrl } from '../actions/configuration';
23
import { refreshVerdicts } from '../actions/data';
34
import type { Action, Dispatch, Store } from '../reducers/types';
@@ -21,6 +22,7 @@ export default (store: Store & { dispatch: Dispatch }) =>
2122
getConfigurationFilterHash(store.getState().configuration) !==
2223
filterBeforeUpdate
2324
) {
25+
logger.info('Configuration filter changed...');
2426
store.dispatch(refreshVerdicts());
2527

2628
if (action.type !== SET_SEARCH_URL) {

app/middleware/data.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '../utils/tracer-logger.js';
12
import type { Action, Dispatch, Store } from '../reducers/types';
23
import { REFRESH_VERDICTS } from '../constants/actionTypes';
34
import { VerdictScope } from '../reducers/data';
@@ -15,6 +16,8 @@ export default (store: Store) => (next: Dispatch) => async (action: Action) => {
1516
} = store.getState();
1617

1718
if (overview) {
19+
logger.debug(`overview ids:${Object.keys(overview)}`);
20+
// logger.log(`full overview:${overview}`);
1821
// we need multiple parts of the state, thus cannot do the this logic in reducers [unclean]
1922
const configurationHash = getConfigurationFilterHash(configuration);
2023
Object.values(overview).forEach((entry: OverviewDataEntry) => {
@@ -32,9 +35,14 @@ export default (store: Store) => (next: Dispatch) => async (action: Action) => {
3235
return;
3336
}
3437

38+
logger.info(
39+
`Refresh verdict for flat ${entry.id} [scope=${currentScope}]`
40+
);
3541
const verdict = assessFlat(configuration, entry, flatData);
3642
store.dispatch(setVerdict(entry.id, verdict));
3743
});
44+
} else {
45+
logger.warn("Have no overview. Isn't this at least '{}'?");
3846
}
3947
}
4048

app/middleware/electron.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { easeInOutCubic } from '../utils/easing';
2727
import resizeViews from '../utils/resizeViews';
2828
import scrollWhileIdle from '../utils/scrollWhileIdle';
2929
import ElectronUtils from '../utils/electronUtils';
30+
import { logger } from '../utils/tracer-logger.js';
3031
import { login } from '../actions/bot';
3132
import electronObjects from '../store/electronObjects';
3233

@@ -36,13 +37,13 @@ export default (store: Store) =>
3637
async (action: Action) => {
3738
if (action.type === ELECTRON_ROUTING) {
3839
const { name, targetUrl } = action.payload;
40+
logger.trace(`url:${targetUrl}`);
3941
store.dispatch(setBrowserViewReady(name, false));
4042
store.dispatch(setBrowserViewUrl(name, targetUrl));
4143
const browserView = electronObjects.views[name];
4244

4345
if (browserView === undefined) {
44-
// eslint-disable-next-line no-console
45-
console.error(`No view registered for ${name}!`);
46+
logger.error(`No view registered for ${name}!`);
4647
} else {
4748
browserView.webContents.loadURL(targetUrl);
4849
}
@@ -52,8 +53,7 @@ export default (store: Store) =>
5253
const { window } = electronObjects;
5354

5455
if (window === undefined || window === null) {
55-
// eslint-disable-next-line no-console
56-
console.error('Main window not defined!');
56+
logger.error('Main window not defined!');
5757
return;
5858
}
5959

@@ -99,6 +99,7 @@ export default (store: Store) =>
9999
}
100100

101101
if (action.type === HIDE_CONFIGURATION) {
102+
logger.info('Close configuration...');
102103
const { immobilienScout24 } = store.getState().configuration;
103104
store.dispatch(login(immobilienScout24));
104105
}

app/middleware/logging.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default (_: Store) => (next: Dispatch) => (action: Action) => {
2323
if (action.constructor && action.constructor.name === 'AsyncFunction') {
2424
const actionAsAsyncFunction = action as unknown as Function;
2525
// eslint-disable-next-line no-console
26-
console.log(
26+
logger.debug(
2727
`[Async Function] ${
2828
actionAsAsyncFunction.name ||
2929
(actionAsAsyncFunction.prototype &&
@@ -32,16 +32,21 @@ export default (_: Store) => (next: Dispatch) => (action: Action) => {
3232
}`
3333
);
3434
} else if (!blackList.includes(action.type)) {
35-
let { payload, type, ...action_less } = action;
35+
let { payload, type, ...other } = action;
3636

37+
logger.debug(`ACTION ${type}`);
38+
39+
let message;
3740
if (payload && JSON.stringify(payload).length > payloadLengthLimit) {
3841
payload = `${JSON.stringify(action.payload).substr(
3942
0,
4043
payloadLengthLimit
4144
)}...`;
45+
message = `payload(short):${payload} other:`;
46+
} else {
47+
message = `payload:${JSON.stringify(payload)} other:`;
4248
}
43-
44-
logger.debug( 'ACTION type:%s \tpayload:%j other:%j', type, payload, action_less);
49+
logger.log(message, other);
4550
}
4651

4752
return next(action);

app/middleware/persistence.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logger } from '../utils/tracer-logger.js';
12
import { WAKE_UP } from '../actions/infrastructure';
23
import { setConfiguration } from '../actions/configuration';
34
import persistentStore from '../utils/persistentStore';
@@ -8,18 +9,19 @@ import { setCache } from '../actions/cache';
89
export default (store: Store) => (next: Dispatch) => (action: Action) => {
910
if (action.type === WAKE_UP) {
1011
// currently without reducer
12+
logger.info('Load configuration...');
1113
const configuration = persistentStore.get('configuration');
12-
1314
if (configuration) {
1415
configuration.loaded = true;
1516
store.dispatch(setConfiguration(configuration));
1617
}
1718

19+
logger.info('Load cache...');
1820
const cache = persistentStore.get('cache');
19-
2021
if (cache) {
2122
store.dispatch(setCache(cache));
2223
}
24+
logger.trace('DONE');
2325
}
2426

2527
// if action contains 'cache: true' then save it before state modification

0 commit comments

Comments
 (0)