Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New synchronous JS function getLogger() + deprecated async function createLogger() #775

Merged
merged 8 commits into from
Oct 11, 2024
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.husky/
.sfdx/
.vscode/
test-coverage/
temp/
test-coverage/
61 changes: 36 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
[![Build](https://github.com/jongpie/NebulaLogger/actions/workflows/build.yml/badge.svg)](https://github.com/jongpie/NebulaLogger/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/jongpie/NebulaLogger/branch/main/graph/badge.svg?token=1DJPDRM3N4)](https://codecov.io/gh/jongpie/NebulaLogger)

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.
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.

## Unlocked Package - v4.14.12
## Unlocked Package - v4.14.13

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

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

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

---

Expand Down Expand Up @@ -157,14 +157,13 @@ This results in 1 `Log__c` record with several related `LogEntry__c` records.
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.

```javascript
// For LWC, import logger's createLogger() function into your component
import { createLogger } from 'c/logger';
// For LWC, import logger's getLogger() function into your component
import { getLogger } from 'c/logger';

export default class LoggerLWCImportDemo extends LightningElement {
logger;
export default class LoggerDemo extends LightningElement {
logger = getLogger();

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

#### Example LWC Usage

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.
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.

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

export default class LoggerLWCImportDemo extends LightningElement {
logger;
export default class LoggerDemo extends LightningElement {
// Call getLogger() once per component
jongpie marked this conversation as resolved.
Show resolved Hide resolved
logger = getLogger();

async connectedCallback() {
// Call createLogger() once per component
this.logger = await createLogger();

this.logger.setScenario('some scenario');
this.logger.finer('initialized demo LWC');
this.logger.finer('initialized demo LWC, using async connectedCallback');
}

@wire(callSomeApexMethod)
wiredCallSomeApexMethod({ error, data }) {
this.logger.info('logging inside a wire function');
if (data) {
this.logger.info('wire function return value: ' + data);
}
if (error) {
this.logger.error('wire function error: ' + JSON.stringify(error));
}
}

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

```javascript
import { createLogger } from 'c/logger';
import { getLogger } from 'c/logger';

export default class LoggerLWCImportDemo extends LightningElement {
logger;
export default class loggerLWCGetLoggerImportDemo extends LightningElement {
logger = getLogger();

async connectedCallback() {
this.logger = await createLogger();
this.logger.info('Hello, world').setField({ SomeCustomTextField__c: 'some text value', SomeCustomNumbertimeField__c: 123 });
this.logger.saveLog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
"components": [
{
"componentAttributes": {},
"componentName": "c:loggerLWCImportDemo",
"componentName": "c:loggerLWCGetLoggerImportDemo",
"id": "715fc8fd-8d07-436a-bbbf-e0f45c93eedc",
"renderPriority": "NEUTRAL",
"renditionMap": {},
"type": "component"
},
{
"componentAttributes": {},
"componentName": "c:loggerLWCCreateLoggerImportDemo",
"id": "ef2d20d3-acfe-49ec-935e-e08ea2c6ec85",
"renderPriority": "NEUTRAL",
"renditionMap": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
"components": [
{
"componentAttributes": {},
"componentName": "c:loggerLWCImportDemo",
"componentName": "c:loggerLWCGetLoggerImportDemo",
"id": "534c7039-bb9e-49b9-a00a-92fdb1665bad",
"renderPriority": "NEUTRAL",
"renditionMap": {},
"type": "component"
},
{
"componentAttributes": {},
"componentName": "c:loggerLWCCreateLoggerImportDemo",
"id": "eb678e7a-f879-4166-9d05-c3287a523795",
"renderPriority": "NEUTRAL",
"renditionMap": {},
Expand Down
4 changes: 2 additions & 2 deletions docs/apex/Logger-Engine/ComponentLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ return The transaction ID (based on `Logger.getTransactionId())`

### Inner Classes

#### ComponentLogger.ComponentBrowser class
#### ComponentLogger.ComponentBrowserContext class

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

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

##### Properties

###### `browser` → `ComponentBrowser`
###### `browser` → `ComponentBrowserContext`

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

Expand Down
Loading