Skip to content

Commit 2445dcb

Browse files
authored
New synchronous JS function getLogger() + deprecated async function createLogger() (#775)
* Fixed #728 by adding a new function getLogger() in logger LWC that can be called synchronously, and deprecated the async function createLogger() * This simplifies how developers use the logger LWC, and avoids some lingering JS stack trace issues that occur in async functions * The function createLogger() is still supported & functional, but it's now considered deprecated since it requires using 'await' * Resolved #763 by adding new logger.exception() JS function (equivalent to the Apex method Logger.exception()) * Fixed #776 by updating logic in loggerStackTrace.js to better handle parsing when lightning debug mode is disabled. Previously, stack traces worked when debug mode was enabled, but were inaccurate when debug mode was off due to some subtle differences in the generated stack traces * Changed recipes metadata to add a new demo LWC for the new/recommended getLogger() function, and updated the existing demo LWC for the createLogger() function to indicate that it's now deprecated * Scope creep: updated LogEntryEventBuilder to always set LoggedByUsername__c using System.UserInfo methods. Previously, it was only set when synchronous querying of User data was enabled
1 parent cfdae6b commit 2445dcb

51 files changed

Lines changed: 2187 additions & 5593 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.husky/
33
.sfdx/
44
.vscode/
5-
test-coverage/
5+
temp/
6+
test-coverage/

README.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
[![Build](https://github.com/jongpie/NebulaLogger/actions/workflows/build.yml/badge.svg)](https://github.com/jongpie/NebulaLogger/actions/workflows/build.yml)
44
[![codecov](https://codecov.io/gh/jongpie/NebulaLogger/branch/main/graph/badge.svg?token=1DJPDRM3N4)](https://codecov.io/gh/jongpie/NebulaLogger)
55

6-
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, Process Builder & integrations.
6+
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.
77

8-
## Unlocked Package - v4.14.12
8+
## Unlocked Package - v4.14.13
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oV0QAI)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oV0QAI)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oW3QAI)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oW3QAI)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://github.com/jongpie/NebulaLogger/wiki)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oV0QAI`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oW3QAI`
1515

16-
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oV0QAI`
16+
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oW3QAI`
1717

1818
---
1919

@@ -157,14 +157,13 @@ This results in 1 `Log__c` record with several related `LogEntry__c` records.
157157
For lightning component developers, the `logger` LWC provides very similar functionality that is offered in Apex. Simply incorporate the `logger` LWC into your component, and call the desired logging methods within your code.
158158

159159
```javascript
160-
// For LWC, import logger's createLogger() function into your component
161-
import { createLogger } from 'c/logger';
160+
// For LWC, import logger's getLogger() function into your component
161+
import { getLogger } from 'c/logger';
162162

163-
export default class LoggerLWCImportDemo extends LightningElement {
164-
logger;
163+
export default class LoggerDemo extends LightningElement {
164+
logger = getLogger();
165165

166-
async connectedCallback() {
167-
this.logger = await createLogger();
166+
connectedCallback() {
168167
this.logger.info('Hello, world');
169168
this.logger.saveLog();
170169
}
@@ -432,21 +431,31 @@ Each `LogEntry__c` record automatically stores the component's type ('Aura' or '
432431

433432
#### Example LWC Usage
434433

435-
For lightning component developers, the `logger` LWC provides very similar functionality that is offered in Apex. Simply import the `logger` LWC in your component, and call the desired logging methods within your code.
434+
For lightning component developers, the `logger` LWC provides very similar functionality that is offered in Apex. Simply import the `getLogger` function in your component, use it to initialize an instance once per component, and call the desired logging methods within your code.
436435

437436
```javascript
438437
// For LWC, import logger's createLogger() function into your component
439-
import { createLogger } from 'c/logger';
438+
import { getLogger } from 'c/logger';
439+
import callSomeApexMethod from '@salesforce/apex/LoggerLWCDemoController.callSomeApexMethod';
440440

441-
export default class LoggerLWCImportDemo extends LightningElement {
442-
logger;
441+
export default class LoggerDemo extends LightningElement {
442+
// Call getLogger() once per component
443+
logger = getLogger();
443444

444445
async connectedCallback() {
445-
// Call createLogger() once per component
446-
this.logger = await createLogger();
447-
448446
this.logger.setScenario('some scenario');
449-
this.logger.finer('initialized demo LWC');
447+
this.logger.finer('initialized demo LWC, using async connectedCallback');
448+
}
449+
450+
@wire(callSomeApexMethod)
451+
wiredCallSomeApexMethod({ error, data }) {
452+
this.logger.info('logging inside a wire function');
453+
if (data) {
454+
this.logger.info('wire function return value: ' + data);
455+
}
456+
if (error) {
457+
this.logger.error('wire function error: ' + JSON.stringify(error));
458+
}
450459
}
451460

452461
logSomeStuff() {
@@ -467,7 +476,10 @@ export default class LoggerLWCImportDemo extends LightningElement {
467476
this.logger.debug('TODO - finishing implementation of doSomething()').addTag('another tag');
468477
// TODO add the function's implementation below
469478
} catch (thrownError) {
470-
this.logger.error('An unexpected error log entry using Nebula Logger with logging level == ERROR').setError(thrownError).addTag('some important tag');
479+
this.logger
480+
.error('An unexpected error log entry using Nebula Logger with logging level == ERROR')
481+
.setExceptionDetails(thrownError)
482+
.addTag('some important tag');
471483
} finally {
472484
this.logger.saveLog();
473485
}
@@ -660,13 +672,12 @@ The first step is to add a field to the platform event `LogEntryEvent__e`
660672
- In JavaScript, populate your field(s) by calling the instance function `LogEntryEventBuilder.setField(Object fieldToValue)`
661673

662674
```javascript
663-
import { createLogger } from 'c/logger';
675+
import { getLogger } from 'c/logger';
664676

665-
export default class LoggerLWCImportDemo extends LightningElement {
666-
logger;
677+
export default class loggerLWCGetLoggerImportDemo extends LightningElement {
678+
logger = getLogger();
667679

668680
async connectedCallback() {
669-
this.logger = await createLogger();
670681
this.logger.info('Hello, world').setField({ SomeCustomTextField__c: 'some text value', SomeCustomNumbertimeField__c: 123 });
671682
this.logger.saveLog();
672683
}

config/scratch-orgs/experience-cloud/experiences/Logger_Test_Aura_Site1/views/home.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
"components": [
2727
{
2828
"componentAttributes": {},
29-
"componentName": "c:loggerLWCImportDemo",
29+
"componentName": "c:loggerLWCGetLoggerImportDemo",
30+
"id": "715fc8fd-8d07-436a-bbbf-e0f45c93eedc",
31+
"renderPriority": "NEUTRAL",
32+
"renditionMap": {},
33+
"type": "component"
34+
},
35+
{
36+
"componentAttributes": {},
37+
"componentName": "c:loggerLWCCreateLoggerImportDemo",
3038
"id": "ef2d20d3-acfe-49ec-935e-e08ea2c6ec85",
3139
"renderPriority": "NEUTRAL",
3240
"renditionMap": {},

config/scratch-orgs/experience-cloud/experiences/Logger_Test_LWR_Site1/views/home.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
"components": [
2121
{
2222
"componentAttributes": {},
23-
"componentName": "c:loggerLWCImportDemo",
23+
"componentName": "c:loggerLWCGetLoggerImportDemo",
24+
"id": "534c7039-bb9e-49b9-a00a-92fdb1665bad",
25+
"renderPriority": "NEUTRAL",
26+
"renditionMap": {},
27+
"type": "component"
28+
},
29+
{
30+
"componentAttributes": {},
31+
"componentName": "c:loggerLWCCreateLoggerImportDemo",
2432
"id": "eb678e7a-f879-4166-9d05-c3287a523795",
2533
"renderPriority": "NEUTRAL",
2634
"renditionMap": {},

docs/apex/Logger-Engine/ComponentLogger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ return The transaction ID (based on `Logger.getTransactionId())`
5555

5656
### Inner Classes
5757

58-
#### ComponentLogger.ComponentBrowser class
58+
#### ComponentLogger.ComponentBrowserContext class
5959

6060
A DTO object used to log details about the user's browser
6161

@@ -123,7 +123,7 @@ A DTO object used to create log entries for lightning components
123123

124124
##### Properties
125125

126-
###### `browser``ComponentBrowser`
126+
###### `browser``ComponentBrowserContext`
127127

128128
Context about the user's browser, automatically captured by Nebula Logger
129129

0 commit comments

Comments
 (0)