Skip to content

Commit

Permalink
Added support for specificying a save method in logger.js, cleaned up…
Browse files Browse the repository at this point in the history
… some comments in Flow classes
  • Loading branch information
jongpie committed Nov 16, 2021
1 parent 7ba4295 commit 47061bd
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 139 deletions.
13 changes: 9 additions & 4 deletions docs/logger-engine/ComponentLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ ComponentLoggerSettings

return The instance of `ComponentLoggerSettings` for the current user

#### `saveComponentLogEntries(List<ComponentLogEntry> componentLogEntries)``String`
#### `saveComponentLogEntries(List<ComponentLogEntry> componentLogEntries, String saveMethodName)``String`

saveComponentLogEntries Saves log entries created via lwc or aura components

##### Parameters

| Param | Description |
| --------------------- | ------------------------------------------------------------ |
| `componentLogEntries` | The list of `ComponentLogEntry` objects to save via `Logger` |
| Param | Description |
| --------------------- | -------------------------------------------------------------------- |
| `componentLogEntries` | The list of `ComponentLogEntry` objects to save via `Logger` |
| `saveMethodName` | String name of the instance of Logger.SaveMethod to use when saving. |

##### Return

Expand Down Expand Up @@ -130,6 +131,10 @@ A DTO object used for passing `LoggerSettings__c` details to lightning component

##### Properties

###### `defaultSaveMethodName``String`

Indicates the save method that will be used by default if no other save method is specified, based on `LoggerSettings__c.DefaultSaveMethod__c`

###### `isConsoleLoggingEnabled``Boolean`

Indicates if logging via the browser&apos;s `console.log()` is enabled for the current user, based on `Logger.IsComponentConsoleLoggingEnabled__c`
Expand Down
2 changes: 1 addition & 1 deletion docs/logger-engine/FlowCollectionLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Optionally log a Flow fault error message

#### `flowName``String`

The name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined
The API name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined

#### `loggingLevelName``String`

Expand Down
6 changes: 3 additions & 3 deletions docs/logger-engine/FlowLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ Optionally log a Flow fault error message

#### `flowName``String`

The name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined.
The API name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined.

#### `loggingLevelName``String`

Optionally specify a logging level - the default is &apos;DEBUG&apos;

#### `message``String`

The message to log.
The message to log

#### `recordId``Id`

Optionally relate the log entry to a particular record ID

#### `saveLog``Boolean`

Optionally choose to save any pending log entries.
Optionally choose to save any pending log entries

#### `saveMethodName``String`

Expand Down
20 changes: 10 additions & 10 deletions docs/logger-engine/FlowLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,47 @@ String containing fault message, if applicable

###### `flowName``String`

name of the flow.
API name of the flow

###### `loggingLevelName``String`

String containing the logging level.
String name of the entry&apos;s logging level

###### `message``String`

General message to log.
General message to log

###### `saveLog``Boolean`

Boolean used to determine if logs are saved to Salesforce.
Boolean used to determine if logs are saved to Salesforce

###### `saveMethodName``String`

String name of the instance of Logger.SaveMethod to use saveLog == true
String name of the instance of Logger.SaveMethod to use when &apos;Save Log&apos; == true

###### `scenario``String`

Optionally specify the name to use for the current transaction&apos;s scenario
Optionally specify the scenario to use for the current transaction

###### `tagsString``String`

String of tags / topics.
Comma-separated string of tags

###### `timestamp``DateTime`

timestamp of the log

###### `topics``List<String>`

List of tags / topics.
List of tags / topics

---

##### Methods

###### `addToLoggerBuffer()``LogEntryEventBuilder`

Adds the logger to the buffer.
Adds the logger to the buffer

####### Return

Expand All @@ -110,6 +110,6 @@ LogEntryEventBuilder

**Description**

An instance of LogEntryEventBuilder.
An instance of LogEntryEventBuilder

---
2 changes: 1 addition & 1 deletion docs/logger-engine/FlowRecordLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Optionally log a Flow fault error message

#### `flowName``String`

The name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined
The API name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined

#### `loggingLevelName``String`

Expand Down
17 changes: 15 additions & 2 deletions nebula-logger/main/logger-engine/classes/ComponentLogger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public inherited sharing class ComponentLogger {
/**
* @description saveComponentLogEntries Saves log entries created via lwc or aura components
* @param componentLogEntries The list of `ComponentLogEntry` objects to save via `Logger`
* @param saveMethodName String name of the instance of Logger.SaveMethod to use when saving.
* When null, the value of `Logger.getSaveMethod()` will be used.
* @return return The transaction ID (based on `Logger.getTransactionId())`
*/
@AuraEnabled
public static String saveComponentLogEntries(List<ComponentLogEntry> componentLogEntries) {
public static String saveComponentLogEntries(List<ComponentLogEntry> componentLogEntries, String saveMethodName) {
try {
Logger.SaveMethod saveMethod = Logger.getSaveMethod();
for (ComponentLogEntry componentLogEntry : componentLogEntries) {
Logger.setScenario(componentLogEntry.scenario);
LoggingLevel entryLoggingLevel = Logger.getLoggingLevel(componentLogEntry.loggingLevel);
Expand All @@ -43,7 +46,10 @@ public inherited sharing class ComponentLogger {
setComponentErrorDetails(logEntryEventBuilder, componentLogEntry.error);
setStackTraceDetails(logEntryEventBuilder, componentLogEntry.stack);
}
Logger.saveLog();
if (String.isNotBlank(saveMethodName) == true) {
saveMethod = Logger.SaveMethod.valueOf(saveMethodName);
}
Logger.saveLog(saveMethod);
return Logger.getTransactionId();
} catch (Exception apexException) {
throw new AuraHandledException(apexException.getMessage());
Expand Down Expand Up @@ -124,6 +130,12 @@ public inherited sharing class ComponentLogger {
* @description A DTO object used for passing `LoggerSettings__c` details to lightning components
*/
public class ComponentLoggerSettings {
/**
* @description Indicates the save method that will be used by default if no other save method is specified, based on `LoggerSettings__c.DefaultSaveMethod__c`
*/
@AuraEnabled
public String defaultSaveMethodName { get; set; }

/**
* @description Indicates if logging is enabled for the current user, based on `LoggerSettings__c.IsEnabled__c`
*/
Expand All @@ -149,6 +161,7 @@ public inherited sharing class ComponentLogger {
public ComponentLoggingLevel userLoggingLevel { get; set; }

private ComponentLoggerSettings() {
this.defaultSaveMethodName = Logger.getSaveMethod().name();
this.isEnabled = Logger.getUserSettings().IsEnabled__c;
this.isConsoleLoggingEnabled = Logger.getUserSettings().IsComponentConsoleLoggingEnabled__c;
this.supportedLoggingLevels = getSupportedLoggingLevels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@SuppressWarnings('PMD.AvoidGlobalModifier')
global inherited sharing class FlowCollectionLogEntry {
/**
* @description The name of the Flow creating the log entry.
* @description The API name of the Flow creating the log entry.
* Due to Salesforce limitations, this cannot be automatically determined
*/
@InvocableVariable(required=true label='Flow API Name')
Expand Down
6 changes: 3 additions & 3 deletions nebula-logger/main/logger-engine/classes/FlowLogEntry.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
@SuppressWarnings('PMD.AvoidGlobalModifier')
global inherited sharing class FlowLogEntry {
/**
* @description The name of the Flow creating the log entry.
* @description The API name of the Flow creating the log entry.
* Due to Salesforce limitations, this cannot be automatically determined.
*/
@InvocableVariable(required=true label='Flow API Name')
global String flowName;

/**
* @description The message to log.
* @description The message to log
*/
@InvocableVariable(required=true label='Log Entry Message')
global String message;
Expand All @@ -34,7 +34,7 @@ global inherited sharing class FlowLogEntry {
global String faultMessage;

/**
* @description Optionally choose to save any pending log entries.
* @description Optionally choose to save any pending log entries
*/
@InvocableVariable(required=false label='(Optional) Save Log')
global Boolean saveLog;
Expand Down
20 changes: 10 additions & 10 deletions nebula-logger/main/logger-engine/classes/FlowLogger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public inherited sharing class FlowLogger {
// Public member variables - all other Flow classes should duplicate these public variables

/**
* @description name of the flow.
* @description API name of the flow
*/
public String flowName;

/**
* @description General message to log.
* @description General message to log
*/
public String message;

Expand All @@ -41,33 +41,33 @@ public inherited sharing class FlowLogger {
public String faultMessage;

/**
* @description String containing the logging level.
* @description String name of the entry's logging level
*/
public String loggingLevelName;

/**
* @description Optionally specify the name to use for the current transaction's scenario
* @description Optionally specify the scenario to use for the current transaction
*/
@InvocableVariable(required=false label='(Optional) Scenario')
public String scenario;

/**
* @description String of tags / topics.
* @description Comma-separated string of tags
*/
public String tagsString;

/**
* @description List of tags / topics.
* @description List of tags / topics
*/
public List<String> topics; // TODO: deprecated, remove in a future release

/**
* @description Boolean used to determine if logs are saved to Salesforce.
* @description Boolean used to determine if logs are saved to Salesforce
*/
public Boolean saveLog = false;

/**
* @description String name of the instance of Logger.SaveMethod to use saveLog == true
* @description String name of the instance of Logger.SaveMethod to use when 'Save Log' == true
*/
public String saveMethodName;

Expand All @@ -82,8 +82,8 @@ public inherited sharing class FlowLogger {
private LogEntryEvent__e logEntryEvent;

/**
* @description Adds the logger to the buffer.
* @return An instance of LogEntryEventBuilder.
* @description Adds the logger to the buffer
* @return An instance of LogEntryEventBuilder
*/
public LogEntryEventBuilder addToLoggerBuffer() {
if (this.logEntryEventBuilder != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@SuppressWarnings('PMD.AvoidGlobalModifier')
global inherited sharing class FlowRecordLogEntry {
/**
* @description The name of the Flow creating the log entry.
* @description The API name of the Flow creating the log entry.
* Due to Salesforce limitations, this cannot be automatically determined
*/
@InvocableVariable(required=true label='Flow API Name')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"defaultSaveMethod": "EVENT_BUS",
"isEnabled": true,
"isConsoleLoggingEnabled": true,
"supportedLoggingLevels": { "FINEST": 2, "FINER": 3, "FINE": 4, "DEBUG": 5, "INFO": 6, "WARN": 7, "ERROR": 8 },
Expand Down
Loading

0 comments on commit 47061bd

Please sign in to comment.