Skip to content

Commit 530a76a

Browse files
util: add new central logger
1 parent d2339ce commit 530a76a

24 files changed

Lines changed: 81 additions & 35 deletions

src/Deputy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import WikiConfiguration from './config/WikiConfiguration';
2323
import Recents from './wiki/Recents';
2424
import util from './util';
2525
import wikiUtil from './wiki/util';
26+
import log from './util/log';
2627
import DeputyAnnouncements from './DeputyAnnouncements';
2728

2829
/**
@@ -169,7 +170,7 @@ class Deputy {
169170
}
170171
await this.wikiConfig.prepareEditBanners();
171172

172-
console.log( 'Loaded!' );
173+
log( 'Loaded!' );
173174

174175
mw.hook( 'deputy.load' ).fire( this );
175176

src/DeputyCommunications.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'broadcastchannel-polyfill';
22
import { ContributionSurveyRowStatus } from './models/ContributionSurveyRow';
33
import generateId from './util/generateId';
44
import { WikiPageConfiguration } from './config/WikiConfiguration';
5+
import log from './util/log';
56

67
/**
78
* Generic message used to acknowledge an action. This is usually required by
@@ -285,7 +286,7 @@ export default class DeputyCommunications extends EventTarget {
285286

286287
this.broadcastChannel.addEventListener( 'message', ( event ) => {
287288
// TODO: debug
288-
console.log( Date.now() - start, '[deputy comms]: in', event.data );
289+
log( Date.now() - start, 'comms in: ', event.data );
289290
if ( event.data && typeof event.data === 'object' && event.data._deputy ) {
290291
this.dispatchEvent(
291292
Object.assign( new Event( event.data.type ), {
@@ -309,7 +310,7 @@ export default class DeputyCommunications extends EventTarget {
309310
);
310311
this.broadcastChannel.postMessage( message );
311312
// TODO: debug
312-
console.log( Date.now() - start, '[deputy comms]: out', data );
313+
log( Date.now() - start, 'comms out:', data );
313314

314315
return message;
315316
}
@@ -355,7 +356,7 @@ export default class DeputyCommunications extends EventTarget {
355356
}
356357
};
357358
handlers.listener = ( ( event: MessageEvent<InboundDeputyMessage> ) => {
358-
console.log( event );
359+
log( event );
359360
if (
360361
event.data._deputyRespondsTo === message._deputyMessageId &&
361362
event.data.type === OneWayDeputyMessageMap[ data.type ]

src/DeputyLanguage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { DeputyResources } from './DeputyResources';
22
import cloneRegex from './util/cloneRegex';
3+
import error from './util/error';
4+
import warn from './util/warn';
35

46
/**
57
* Handles internationalization and localization for Deputy and sub-modules.
@@ -40,7 +42,7 @@ export default class DeputyLanguage {
4042
mw.messages.set( key, langData[ key ] );
4143
}
4244
} catch ( e ) {
43-
console.error( e );
45+
error( e );
4446
mw.notify(
4547
// No languages to fall back on. Do not translate this string.
4648
'Deputy: Requested language page is not a valid JSON file.',
@@ -73,7 +75,7 @@ export default class DeputyLanguage {
7375

7476
if ( mw.loader.getState( 'moment' ) !== 'ready' ) {
7577
// moment.js is not yet loaded.
76-
console.warn(
78+
warn(
7779
'Deputy tried loading moment.js locales but moment.js is not yet ready.'
7880
);
7981
return;
@@ -136,7 +138,7 @@ export default class DeputyLanguage {
136138
}
137139
} catch ( e ) {
138140
// Silent failure.
139-
console.error( 'Deputy: Requested language page is not a valid JSON file.', e );
141+
error( 'Deputy: Requested language page is not a valid JSON file.', e );
140142
}
141143
}
142144

src/DeputyStorage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { openDB, DBSchema, IDBPDatabase } from 'idb';
22
import { ExpandedRevisionData } from './api/ExpandedRevisionData';
33
import { ContributionSurveyRowStatus } from './models/ContributionSurveyRow';
44
import MwApi from './MwApi';
5+
import log from './util/log';
56

67
/**
78
* General key-value store. Used for storing single-variable data
@@ -122,8 +123,8 @@ export default class DeputyStorage {
122123
};
123124
while ( currentVersion < newVersion ) {
124125
upgrader[ `${currentVersion}` ]();
125-
console.log(
126-
`[deputy] upgraded database from ${currentVersion} to ${
126+
log(
127+
`Upgraded database from ${currentVersion} to ${
127128
currentVersion + 1
128129
}`
129130
);

src/config/Setting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import UserConfiguration from './UserConfiguration';
55
import { ArrayOrNot } from '../types';
66
import getObjectValues from '../util/getObjectValues';
7+
import warn from '../util/warn';
78

89
interface DisplayOptionsBase {
910

@@ -225,7 +226,7 @@ export default class Setting<SerializedType, DeserializedType> {
225226
*/
226227
set( v: DeserializedType, throwOnInvalid = false ) {
227228
if ( this.locked ) {
228-
console.warn( 'Attempted to modify locked setting.' );
229+
warn( 'Attempted to modify locked setting.' );
229230
return;
230231
}
231232

src/config/UserConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ConfigurationBase from './ConfigurationBase';
99
import {
1010
ContributionSurveyRowSigningBehavior
1111
} from '../models/ContributionSurveyRowSigningBehavior';
12+
import error from '../util/error';
1213

1314
/**
1415
* A configuration. Defines settings and setting groups.
@@ -31,7 +32,7 @@ export default class UserConfiguration extends ConfigurationBase {
3132
config.deserialize( decodedOptions );
3233
}
3334
} catch ( e ) {
34-
console.error( e, mw.user.options.get( UserConfiguration.optionKey ) );
35+
error( e, mw.user.options.get( UserConfiguration.optionKey ) );
3536
mw.hook( 'deputy.i18nDone' ).add( function notifyConfigFailure() {
3637
mw.notify( mw.msg( 'deputy.loadError.userConfig' ), {
3738
type: 'error'

src/modules/DeputyModule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import deputySharedEnglish from '../../i18n/shared/en.json';
55
import UserConfiguration from '../config/UserConfiguration';
66
import { attachConfigurationDialogPortletLink } from '../ui/config/ConfigurationDialog';
77
import WikiConfiguration from '../config/WikiConfiguration';
8+
import warn from '../util/warn';
89

910
/**
1011
* A Deputy module. Modules are parts of Deputy that can usually be removed
@@ -112,7 +113,7 @@ export default abstract class DeputyModule {
112113

113114
if ( this.wikiConfig[ this.getName() as 'ia' | 'ante' ]?.enabled.get() !== true ) {
114115
// Stop loading here.
115-
console.warn( `[Deputy] Preinit for ${
116+
warn( `Preinit for ${
116117
this.getName()
117118
} cancelled; module is disabled.` );
118119
return false;

src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import equalTitle from '../../../../util/equalTitle';
1515
import RevisionDateGetButton from '../components/RevisionDateGetButton';
1616
import SmartTitleInputWidget from '../components/SmartTitleInputWidget';
1717
import PageLatestRevisionGetButton from '../components/PageLatestRevisionGetButton';
18+
import error from '../../../../util/error';
1819
import dangerModeConfirm from '../../../../util/dangerModeConfirm';
1920
import parseDiffUrl from '../../../../wiki/util/parseDiffUrl';
2021

@@ -613,7 +614,7 @@ function initCopiedTemplateRowPage() {
613614
} );
614615
confirmProcess.execute();
615616
} catch ( e ) {
616-
console.error( 'Cannot convert `diff` parameter to URL.', e );
617+
error( 'Cannot convert `diff` parameter to URL.', e );
617618
OO.ui.alert( mw.msg( 'deputy.ante.copied.diffDeprecate.failed' ) );
618619
}
619620
}

src/modules/ia/models/CopyrightProblemsListing.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import pagelinkToTitle from '../../../wiki/util/pagelinkToTitle';
55
import decorateEditSummary from '../../../wiki/util/decorateEditSummary';
66
import MwApi from '../../../MwApi';
77
import changeTag from '../../../config/changeTag';
8+
import warn from '../../../util/warn';
89

910
export interface SerializedCopyrightProblemsListingData {
1011
basic: boolean;
@@ -175,7 +176,7 @@ export default class CopyrightProblemsListing {
175176
} else if ( title.getPrefixedText() !== new mw.Title( id ).getPrefixedText() ) {
176177
// Anchor and link mismatch. Someone tampered with the template?
177178
// In this case, rely on the link instead, as the anchor is merely invisible.
178-
console.warn(
179+
warn(
179180
`Anchor and link mismatch for "${title.getPrefixedText()}".`, title, id
180181
);
181182
}
@@ -217,7 +218,7 @@ export default class CopyrightProblemsListing {
217218
plainlinks: plainlinks as HTMLSpanElement
218219
};
219220
} catch ( e ) {
220-
console.warn( "Couldn't parse listing. Might be malformed?", e, el );
221+
warn( "Couldn't parse listing. Might be malformed?", e, el );
221222
return false;
222223
}
223224
}
@@ -276,7 +277,7 @@ export default class CopyrightProblemsListing {
276277
element: el as HTMLAnchorElement
277278
};
278279
} catch ( e ) {
279-
console.warn( "Couldn't parse listing. Might be malformed?", e, el );
280+
warn( "Couldn't parse listing. Might be malformed?", e, el );
280281
return false;
281282
}
282283
}

src/modules/ia/ui/ListingResponsePanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type CopyrightProblemsListing from '../models/CopyrightProblemsListing';
55
import removeElement from '../../../util/removeElement';
66
import renderWikitext from '../../../wiki/util/renderWikitext';
77
import { CopyrightProblemsResponse } from '../models/CopyrightProblemsResponse';
8+
import error from '../../../util/error';
89

910
/**
1011
*
@@ -186,7 +187,7 @@ export default class ListingResponsePanel extends EventTarget {
186187
type: 'success'
187188
} );
188189
} catch ( e ) {
189-
console.error( e );
190+
error( e );
190191
OO.ui.alert( mw.msg( 'deputy.ia.listing.re.error', e.message ) );
191192

192193
this.dropdown.setDisabled( false );

0 commit comments

Comments
 (0)