Skip to content

Commit 6c4912a

Browse files
committed
Improved log messages and log levels
1 parent 9b09259 commit 6c4912a

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

packages/core/src/configuration/SettingsManager.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ export class SettingsManager {
1313
private static _isUpdatingSettings: boolean = false;
1414

1515
public static applySavedServerSettings(config: Configuration): void {
16-
if (!config || !config.isValid) {
16+
if (!config?.isValid) {
1717
return;
1818
}
1919

2020
const savedSettings = this.getSavedServerSettings(config);
21-
config.services.log.info(`Applying saved settings: v${savedSettings.version}`);
21+
config.services.log.trace(`Applying saved settings: v${savedSettings.version}`);
2222
config.settings = merge(config.settings, savedSettings.settings);
2323
}
2424

2525
public static getVersion(config: Configuration): number {
26-
if (!config || !config.isValid) {
26+
if (!config?.isValid) {
2727
return 0;
2828
}
2929

@@ -42,22 +42,22 @@ export class SettingsManager {
4242
}
4343

4444
public static async updateSettings(config: Configuration, version?: number): Promise<void> {
45-
if (!config || !config.enabled || this._isUpdatingSettings) {
45+
if (!config?.enabled || this._isUpdatingSettings) {
4646
return;
4747
}
4848

4949
const { log } = config.services;
5050
const unableToUpdateMessage = "Unable to update settings";
5151
if (!config.isValid) {
52-
log.error(`${unableToUpdateMessage}: ApiKey is not set.`);
52+
log.error(`${unableToUpdateMessage}: ApiKey is not set`);
5353
return;
5454
}
5555

5656
if (!version || version < 0) {
5757
version = this.getVersion(config);
5858
}
5959

60-
log.info(`Checking for updated settings from: v${version}.`);
60+
log.trace(`Checking for updated settings from: v${version}`);
6161
this._isUpdatingSettings = true;
6262
const response = await config.services.submissionClient.getSettings(version);
6363
try {
@@ -66,13 +66,14 @@ export class SettingsManager {
6666
return;
6767
}
6868

69-
const settings = merge(config.settings, response.data.settings);
69+
const data = JSON.parse(response.data);
70+
const settings = merge(config.settings, data.settings);
7071

7172
// TODO: Store snapshot of settings after reading from config and attributes and use that to revert to defaults.
7273
// Remove any existing server settings that are not in the new server settings.
7374
const savedServerSettings = SettingsManager.getSavedServerSettings(config);
7475
for (const key in savedServerSettings) {
75-
if (response.data.settings[key]) {
76+
if (data.settings[key]) {
7677
continue;
7778
}
7879

@@ -81,7 +82,7 @@ export class SettingsManager {
8182

8283
config.settings = settings;
8384
config.services.storage.settings.save(response.data);
84-
log.info(`Updated settings: v${response.data.version}`);
85+
log.trace(`Updated settings: v${data.version}`);
8586
} finally {
8687
this._isUpdatingSettings = false;
8788
}

packages/core/src/queue/DefaultEventQueue.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export class DefaultEventQueue implements IEventQueue {
6969
this.ensureQueueTimer();
7070

7171
const timestamp = config.services.storage.queue.save(event);
72-
const logText = `type=${event.type} ${event.reference_id ? "refid=" + event.reference_id : ""}`;
72+
const logText = `type=${event.type} ${event.reference_id ? "refid=" + event.reference_id : ""} source=${event.source} message=${event.message}`;
7373
if (timestamp) {
7474
log.info(`Enqueuing event: ${timestamp} ${logText}`);
7575
} else {
76-
log.error(`Could not enqueue event ${logText}`);
76+
log.error(`Could not enqueue event: ${logText}`);
7777
}
7878
}
7979

@@ -86,7 +86,7 @@ export class DefaultEventQueue implements IEventQueue {
8686
return;
8787
}
8888

89-
log.info("Processing queue...");
89+
log.trace("Processing queue...");
9090
if (!this.config.enabled) {
9191
log.info(`Configuration is disabled: ${queueNotProcessed}`);
9292
return;
@@ -111,7 +111,7 @@ export class DefaultEventQueue implements IEventQueue {
111111
const response = await this.config.services.submissionClient.submitEvents(events.map((e) => e.value));
112112
this.processSubmissionResponse(response, events);
113113
this.eventsPosted(events.map((e) => e.value), response);
114-
log.info("Finished processing queue.");
114+
log.trace("Finished processing queue.");
115115
this._processingQueue = false;
116116
} catch (ex) {
117117
log.error(`Error processing queue: ${ex}`);
@@ -194,32 +194,28 @@ export class DefaultEventQueue implements IEventQueue {
194194
const log: ILog = config.services.log; // Optimization for minifier.
195195

196196
if (response.status === 202) {
197-
log.info(`Sent ${events.length} events.`);
197+
log.info(`Sent ${events.length} events`);
198198
this.removeEvents(events);
199199
return;
200200
}
201201

202202
if (response.status === 429 || response.rateLimitRemaining === 0 || response.status === 503) {
203203
// You are currently over your rate limit or the servers are under stress.
204-
log.error("Server returned service unavailable.");
204+
log.error("Server returned service unavailable");
205205
this.suspendProcessing();
206206
return;
207207
}
208208

209209
if (response.status === 402) {
210210
// If the organization over the rate limit then discard the event.
211-
log.info(
212-
"Too many events have been submitted, please upgrade your plan.",
213-
);
211+
log.info("Too many events have been submitted, please upgrade your plan");
214212
this.suspendProcessing(null, true, true);
215213
return;
216214
}
217215

218216
if (response.status === 401 || response.status === 403) {
219217
// The api key was suspended or could not be authorized.
220-
log.info(
221-
`Unable to authenticate, please check your configuration. ${noSubmission}`,
222-
);
218+
log.info(`Unable to authenticate, please check your configuration. ${noSubmission}`);
223219
this.suspendProcessing(15);
224220
this.removeEvents(events);
225221
return;

0 commit comments

Comments
 (0)