Skip to content

Commit

Permalink
Logger LWC Enhancements (#401)
Browse files Browse the repository at this point in the history
* Updated logger lwc to provide the ability to import the new function createLogger(), which returns an instance of LoggerService. This provides support for logging in lifecycle events that don't work with the previously-used markup approach.

* Refactored now-deprecated @api methods in logger.js to internally use an instance of LoggerService to reduce code duplication

* Added improved formatting of console message in logEntryBuilder.js

* Added version number and console statement to logger.js

* Added all lifecycle events & logging in loggerLWCDemo.js

* Added new recipes LWC loggerLWCLegacyDemo to show how the now-deprecated (but still supported) markup-based approach can be used for logging in lightning components

---------

Co-authored-by: Jonathan Gillespie <jonathan.c.gillespie@gmail.com>
  • Loading branch information
jefersonchaves and jongpie authored May 22, 2023
1 parent d090f6a commit 695887d
Show file tree
Hide file tree
Showing 20 changed files with 1,296 additions and 387 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.

## Unlocked Package - v4.10.1
## Unlocked Package - v4.10.2

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

`sfdx package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015nYaQAI`
`sfdx package install --wait 20 --security-type AdminsOnly --package 04t5Y0000023S8jQAE`

## Managed Package - v4.10.0

Expand Down
17 changes: 8 additions & 9 deletions docs/lightning-components/LogEntryBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Kind**: global class

- [LogEntryBuilder](#LogEntryBuilder)
- [new LogEntryBuilder(loggingLevel, shouldSave, isConsoleLoggingEnabled)](#new_LogEntryBuilder_new)
- [new LogEntryBuilder(loggingLevel, isConsoleLoggingEnabled)](#new_LogEntryBuilder_new)
- [.setMessage(message)](#LogEntryBuilder+setMessage) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
- [.setRecordId(recordId)](#LogEntryBuilder+setRecordId) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
- [.setRecord(record)](#LogEntryBuilder+setRecord) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
Expand All @@ -15,15 +15,14 @@

<a name="new_LogEntryBuilder_new"></a>

### new LogEntryBuilder(loggingLevel, shouldSave, isConsoleLoggingEnabled)
### new LogEntryBuilder(loggingLevel, isConsoleLoggingEnabled)

Constructor used to generate each JavaScript-based log entry event
This class is the JavaScript-equivalent of the Apex class `LogEntryBuilder`

| Param | Type | Description |
| ----------------------- | -------------------- | ------------------------------------------------------------------------------- |
| loggingLevel | <code>String</code> | The `LoggingLevel` enum to use for the builder's instance of `LogEntryEvent__e` |
| shouldSave | <code>Boolean</code> | Determines if the builder's instance of `LogEntryEvent__e` should be saved |
| isConsoleLoggingEnabled | <code>Boolean</code> | Determines if `console.log()` methods are execute |

<a name="LogEntryBuilder+setMessage"></a>
Expand All @@ -32,7 +31,7 @@ This class is the JavaScript-equivalent of the Apex class `LogEntryBuilder`

Sets the log entry event's message field

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -45,7 +44,7 @@ Sets the log entry event's message field

Sets the log entry event's record fields

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -58,7 +57,7 @@ Sets the log entry event's record fields

Sets the log entry event's record fields

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -71,7 +70,7 @@ Sets the log entry event's record fields

Sets the log entry event's exception fields

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -84,7 +83,7 @@ Sets the log entry event's exception fields

Appends the tag to the existing list of tags

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -97,7 +96,7 @@ Appends the tag to the existing list of tags

Appends the tag to the existing list of tags

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: [<code>LogEntryBuilder</code>](#LogEntryBuilder) - The same instance of `LogEntryBuilder`, useful for chaining methods

| Param | Type | Description |
Expand Down
74 changes: 45 additions & 29 deletions docs/lightning-components/Logger.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Functions

<dl>
<dt><a href="#getUserSettings">getUserSettings()</a> <code>ComponentLogger.ComponentLoggerSettings</code></dt>
<dd><p>Returns information about the current user&#39;s settings, stored in <code>LoggerSettings__c</code></p>
<dt><a href="#getUserSettings">getUserSettings(parameters)</a> <code>Promise.&lt;ComponentLogger.ComponentLoggerSettings&gt;</code></dt>
<dd><p>Returns <strong>read-only</strong> information about the current user&#39;s settings, stored in <code>LoggerSettings__c</code></p>
</dd>
<dt><a href="#setScenario">setScenario(scenario)</a></dt>
<dt><a href="#setScenario">setScenario(scenario)</a> <code>Array.&lt;Promise&gt;</code></dt>
<dd><p>Sets the scenario name for the current transaction - this is stored in <code>LogEntryEvent__e.Scenario__c</code>
and <code>Log__c.TransactionScenario__c</code>, and can be used to filter &amp; group logs</p>
and <code>Log__c.Scenario__c</code>, and can be used to filter &amp; group logs</p>
</dd>
<dt><a href="#error">error(message)</a> <code>LogEntryBuilder</code></dt>
<dd><p>Creates a new log entry with logging level == <code>LoggingLevel.ERROR</code></p>
Expand All @@ -32,31 +32,39 @@
<dt><a href="#getBufferSize">getBufferSize()</a> <code>Integer</code></dt>
<dd><p>Returns the number of entries that have been generated but not yet saved</p>
</dd>
<dt><a href="#flushBuffer">flushBuffer()</a></dt>
<dt><a href="#flushBuffer">flushBuffer()</a> <code>Promise.&lt;void&gt;</code></dt>
<dd><p>Discards any entries that have been generated but not yet saved</p>
</dd>
<dt><a href="#saveLog">saveLog(saveMethod)</a></dt>
<dd><p>Saves any entries in Logger&#39;s buffer, using the specified save method for only this call.
All subsequent calls to saveLog() will use the transaction save method.</p>
<dd><p>Saves any entries in Logger&#39;s buffer, using the specified save method for only this call
All subsequent calls to saveLog() will use the transaction save method</p>
</dd>
<dt><a href="#createLogger">createLogger()</a> <code>LoggerService</code></dt>
<dd></dd>
</dl>

<a name="getUserSettings"></a>

## getUserSettings() <code>ComponentLogger.ComponentLoggerSettings</code>
## getUserSettings(parameters) <code>Promise.&lt;ComponentLogger.ComponentLoggerSettings&gt;</code>

Returns information about the current user's settings, stored in `LoggerSettings__c`
Returns **read-only** information about the current user's settings, stored in `LoggerSettings__c`

**Kind**: global function
**Returns**: <code>Promise.&lt;ComponentLogger.ComponentLoggerSettings&gt;</code> - The current user's instance of the Apex class `ComponentLogger.ComponentLoggerSettings`

| Param | Type | Description |
| ---------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| parameters | <code>Object</code> | Object used to provide control over how user settings are retrieved. Currently, only the property `forceReload` is used. |

**Kind**: global function
**Returns**: <code>ComponentLogger.ComponentLoggerSettings</code> - The current user's instance of the Apex class `ComponentLogger.ComponentLoggerSettings`
<a name="setScenario"></a>

## setScenario(scenario)
## setScenario(scenario) <code>Array.&lt;Promise&gt;</code>

Sets the scenario name for the current transaction - this is stored in `LogEntryEvent__e.Scenario__c`
and `Log__c.Scenario__c`, and can be used to filter & group logs

**Kind**: global function
**Kind**: global function
**Returns**: <code>Array.&lt;Promise&gt;</code> - A list of promises that be resolved before all scenarios are set

| Param | Type | Description |
| -------- | ------------------- | ------------------------------------------------------ |
Expand All @@ -68,7 +76,7 @@ and `Log__c.Scenario__c`, and can be used to filter & group logs

Creates a new log entry with logging level == `LoggingLevel.ERROR`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -81,7 +89,7 @@ Creates a new log entry with logging level == `LoggingLevel.ERROR`

Creates a new log entry with logging level == `LoggingLevel.WARN`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -94,7 +102,7 @@ Creates a new log entry with logging level == `LoggingLevel.WARN`

Creates a new log entry with logging level == `LoggingLevel.INFO`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -107,7 +115,7 @@ Creates a new log entry with logging level == `LoggingLevel.INFO`

Creates a new log entry with logging level == `LoggingLevel.DEBUG`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -120,7 +128,7 @@ Creates a new log entry with logging level == `LoggingLevel.DEBUG`

Creates a new log entry with logging level == `LoggingLevel.FINE`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -133,7 +141,7 @@ Creates a new log entry with logging level == `LoggingLevel.FINE`

Creates a new log entry with logging level == `LoggingLevel.FINER`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -146,7 +154,7 @@ Creates a new log entry with logging level == `LoggingLevel.FINER`

Creates a new log entry with logging level == `LoggingLevel.FINEST`

**Kind**: global function
**Kind**: global function
**Returns**: <code>LogEntryBuilder</code> - The new entry's instance of `LogEntryEventBuilder`, useful for chaining methods

| Param | Type | Description |
Expand All @@ -159,24 +167,32 @@ Creates a new log entry with logging level == `LoggingLevel.FINEST`

Returns the number of entries that have been generated but not yet saved

**Kind**: global function
**Returns**: <code>Integer</code> - The buffer's current size
**Kind**: global function
**Returns**: <code>Integer</code> - The buffer's current size
<a name="flushBuffer"></a>

## flushBuffer()
## flushBuffer() <code>Promise.&lt;void&gt;</code>

Discards any entries that have been generated but not yet saved

**Kind**: global function
**Kind**: global function
**Returns**: <code>Promise.&lt;void&gt;</code> - A promise to clear the entries
<a name="saveLog"></a>

## saveLog(saveMethod)

Saves any entries in Logger's buffer, using the specified save method for only this call.
All subsequent calls to saveLog() will use the transaction save method.
Saves any entries in Logger's buffer, using the specified save method for only this call
All subsequent calls to saveLog() will use the transaction save method

**Kind**: global function

| Param | Type | Description |
| ---------- | ------------------- | ------------------------------------------------------------------------- |
| saveMethod | <code>String</code> | The enum value of Logger.SaveMethod to use for this specific save action. |
| Param | Type | Description |
| ---------- | ------------------- | ------------------------------------------------------------------------ |
| saveMethod | <code>String</code> | The enum value of Logger.SaveMethod to use for this specific save action |

<a name="createLogger"></a>

## createLogger() <code>LoggerService</code>

**Kind**: global function
**Returns**: <code>LoggerService</code> - a LoggerService instance
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.10.1';
private static final String CURRENT_VERSION_NUMBER = 'v4.10.2';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final Set<String> IGNORED_APEX_CLASSES = initializeIgnoredApexClasses();
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
Expand Down
Loading

0 comments on commit 695887d

Please sign in to comment.