Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Sep 20, 2024
1 parent 8a6a54d commit befeb37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createElement } from 'lwc';
import FORM_FACTOR from '@salesforce/client/formFactor';
// Recommended approach
import { createLogger } from 'c/logger';
import { createLogger, getLogger } from 'c/logger';
// Legacy approach
import Logger from 'c/logger';
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
Expand Down Expand Up @@ -44,6 +44,7 @@ describe('logger lwc import tests', () => {

it('sets a log scenario on all entries when using recommended import approach', async () => {
getSettings.mockResolvedValue({ ...MOCK_GET_SETTINGS });
// const logger = getLogger();
const logger = await createLogger();
const scenario = 'some scenario';
const message = 'some message';
Expand Down Expand Up @@ -141,7 +142,6 @@ describe('logger lwc import tests', () => {

const logEntry = logger.finest(message).getComponentLogEntry();

await flushPromises();
expect(logger.getBufferSize()).toEqual(1);
expect(logEntry.loggingLevel).toEqual('FINEST');
expect(logEntry.message).toEqual(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ const LoggerService = class {
_newEntry(loggingLevel, message, originStackTraceError) {
originStackTraceError = originStackTraceError ?? new Error();
const logEntryBuilder = newLogEntry(loggingLevel).parseStackTrace(originStackTraceError).setMessage(message).setScenario(this.#scenario);
const logEntry = logEntryBuilder.getComponentLogEntry();
logEntry.scenario = this.#scenario;

const loggingLevelCheckTask = providedLoggingLevel => {
if (this._meetsUserLoggingLevel(providedLoggingLevel)) {
this.#componentLogEntries.push(logEntryBuilder.getComponentLogEntry());
this.#componentLogEntries.push(logEntry);

if (this.#settings.isConsoleLoggingEnabled) {
logEntryBuilder.logToConsole();
Expand All @@ -143,6 +145,7 @@ const LoggerService = class {
}
};
this.#taskQueue.enqueueTask(loggingLevelCheckTask, loggingLevel);
this.#taskQueue.processTaskQueue();

return logEntryBuilder;
}
Expand All @@ -159,7 +162,10 @@ const getLoggerService = function () {
};

const createLoggerService = async function () {
return Promise.resolve(getLoggerService());
const service = new LoggerService();
await service._loadSettingsFromServer();
await Promise.resolve();
return service;
};

export { createLoggerService, getLoggerService };

0 comments on commit befeb37

Please sign in to comment.