Skip to content

Commit

Permalink
Store HttpResponse header values (#564)
Browse files Browse the repository at this point in the history
* Resolved #561 by adding new fields LogEntryEvent__e.HttpResponseHeaders__c and LogEntry__c.HttpResponseHeaders__c that store the full key-value pair for each header

* Added new LoggerParameter__mdt record StoreHttpResponseHeaderValues to globally control if HttpResponse header values are stored

* Bulk updated the convention used throughout the codebase for checking Booleans from 'if(condition == true)' to just 'if(condition)'
  • Loading branch information
jongpie committed Oct 6, 2023
1 parent a5a960f commit d1ed36e
Show file tree
Hide file tree
Showing 64 changed files with 502 additions and 344 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

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

## Unlocked Package - v4.11.7
## Unlocked Package - v4.11.8

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

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001HZfaQAG`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Oig9QAC`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001HZfaQAG`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Oig9QAC`

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public with sharing class MyProfilePageControllerTest {
// System.Assert.areEqual(currentUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
// System.Assert.isTrue(controller.getIsEdit() == false, 'isEdit should default to false');
controller.edit();
// System.Assert.isTrue(controller.getIsEdit() == true);
// System.Assert.isTrue(controller.getIsEdit());
controller.cancel();
// System.Assert.isTrue(controller.getIsEdit() == false);

Expand All @@ -41,7 +41,7 @@ public with sharing class MyProfilePageControllerTest {
// System.Assert.areEqual(existingPortalUser.Id, controller.getUser().Id, 'Did not successfully load the current user');
// System.Assert.isTrue(controller.getIsEdit() == false, 'isEdit should default to false');
controller.edit();
// System.Assert.isTrue(controller.getIsEdit() == true);
// System.Assert.isTrue(controller.getIsEdit());

controller.cancel();
// System.Assert.isTrue(controller.getIsEdit() == false);
Expand Down
4 changes: 4 additions & 0 deletions docs/apex/Configuration/LoggerParameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ Indicates if Nebula Logger queries `User` data is queried synchronously & po

Indicates if Nebula Logger will send an error email notification if any internal exceptions occur. Controlled by the custom metadata record `LoggerParameter.SendErrorEmailNotifications`, or `true` as the default

#### `STORE_HTTP_RESPONSE_HEADER_VALUES``Boolean`

Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpResponse`. Controlled by the custom metadata record `LoggerParameter.StoreHttpResponseHeaderValues`, or `true` as the default. Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of `System.HttpResponse` that is logged - this parameter only controls if the header values are stored.

#### `SYSTEM_DEBUG_MESSAGE_FORMAT``String`

The merge-field syntax to use when calling System.debug(). Controlled by the custom metadata record `LoggerParameter.SystebugMessageFormat`, or `{OriginLocation__c}\n{Message__c}` as the default
Expand Down
2 changes: 1 addition & 1 deletion docs/apex/Configuration/LoggerPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The list of matching `LoggerPlugin_t` records

#### `getPluginConfigurations()``List<LoggerPlugin_t>`

Returns all enabled `LoggerPlugin_t` records, based on `IsEnabled__c == true`
Returns all enabled `LoggerPlugin_t` records (where `IsEnabled__c` is set to `true`)

##### Return

Expand Down
2 changes: 1 addition & 1 deletion docs/apex/Logger-Engine/FlowLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Boolean used to determine if logs are saved to Salesforce

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/apex/Logger-Engine/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -4738,7 +4738,7 @@ Boolean

#### `newEntry(System.LoggingLevel loggingLevel, LogMessage logMessage, Boolean shouldSave)``LogEntryEventBuilder`

Adds a new instance of LogEntryEventBuilder to Logger&apos;s buffer, if shouldSave == true
Adds a new instance of LogEntryEventBuilder to Logger&apos;s buffer, when `shouldSave` is `true`

##### Parameters

Expand Down
96 changes: 52 additions & 44 deletions docs/apex/Test-Utilities/LoggerMockDataCreator.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ Creates a mock instance of `Database.DeleteResult` - a mock is used instead of a

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |

##### Return

Expand All @@ -96,10 +96,10 @@ Creates a mock instance of `Database.DeleteResult` - a mock is used instead of a

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand All @@ -117,9 +117,9 @@ Creates a mock instance of `Database.LeadConvertResult` - a mock is used instead

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |

##### Return

Expand All @@ -137,10 +137,10 @@ Creates a mock instance of `Database.LeadConvertResult` - a mock is used instead

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand All @@ -158,9 +158,9 @@ Creates a mock instance of `Database.MergeResult` - a mock is used instead of an

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |

##### Return

Expand All @@ -178,10 +178,10 @@ Creates a mock instance of `Database.MergeResult` - a mock is used instead of an

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand All @@ -199,9 +199,9 @@ Creates a mock instance of `Database.SaveResult` - a mock is used instead of an

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |

##### Return

Expand All @@ -219,10 +219,10 @@ Creates a mock instance of `Database.SaveResult` - a mock is used instead of an

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand All @@ -240,9 +240,9 @@ Creates a mock instance of `Database.UndeleteResult` - a mock is used instead of

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |

##### Return

Expand All @@ -260,10 +260,10 @@ Creates a mock instance of `Database.UndeleteResult` - a mock is used instead of

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand All @@ -281,10 +281,10 @@ Creates a mock instance of `Database.UpsertResult` - a mock is used instead of a

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `isCreated` | Indicates if the generated mock should have `isCreated` == true |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `isCreated` | Indicates if the generated mock should have `isCreated` |

##### Return

Expand All @@ -302,11 +302,11 @@ Creates a mock instance of `Database.UpsertResult` - a mock is used instead of a

##### Parameters

| Param | Description |
| ----------- | --------------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` == true |
| `isCreated` | Indicates if the generated mock should have `isCreated` == true |
| `recordId` | The record ID to use within the mock result |
| Param | Description |
| ----------- | ------------------------------------------------------- |
| `isSuccess` | Indicates if the generated mock should have `isSuccess` |
| `isCreated` | Indicates if the generated mock should have `isCreated` |
| `recordId` | The record ID to use within the mock result |

##### Return

Expand Down Expand Up @@ -550,6 +550,8 @@ A new copy of the original `SObject` record that has the specified read-only fie

##### Constructors

###### `MockBatchableContext()`

###### `MockBatchableContext(Id jobId)`

###### `MockBatchableContext(Id jobId, Id childJobId)`
Expand All @@ -570,6 +572,8 @@ A new copy of the original `SObject` record that has the specified read-only fie

##### Constructors

###### `MockFinalizerContext()`

###### `MockFinalizerContext(Id asyncApexJobId)`

---
Expand Down Expand Up @@ -628,6 +632,8 @@ A new copy of the original `SObject` record that has the specified read-only fie

##### Constructors

###### `MockQueueableContext()`

###### `MockQueueableContext(Id jobId)`

---
Expand All @@ -644,6 +650,8 @@ A new copy of the original `SObject` record that has the specified read-only fie

##### Constructors

###### `MockSchedulableContext()`

###### `MockSchedulableContext(Id triggerId)`

---
Expand Down
4 changes: 2 additions & 2 deletions docs/apex/Test-Utilities/LoggerTestConfigurator.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ Loads the mock `LogStatus_t` during test execution

#### `setupMockSObjectHandlerConfigurations()``void`

Creates mock instances of `LoggerSObjectHandler_t` for each `SObjectType` used by Nebula Logger, with each `LoggerSObjectHandler_t` automatically set to `IsEnabled__c == true`
Creates mock instances of `LoggerSObjectHandler_t` for each `SObjectType` used by Nebula Logger, with `IsEnabled__c` set to `true` on each `LoggerSObjectHandler_t` record

#### `setupMockSObjectHandlerConfigurations(Boolean isEnabled)``void`

Creates mock instances of `LoggerSObjectHandler_t` for each `SObjectType` used by Nebula Logger, with each `LoggerSObjectHandler_t` enabled/disabled based on the provided boolean
Creates mock instances of `LoggerSObjectHandler_t` for each `SObjectType` used by Nebula Logger, with `IsEnabled__c` set based on the provided boolean on each `LoggerSObjectHandler_t` record

##### Parameters

Expand Down
4 changes: 2 additions & 2 deletions nebula-logger/core/main/configuration/classes/LoggerCache.cls
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public without sharing class LoggerCache {
public void put(String key, Object value) {
this.transactionCache.put(key, value);

if (LoggerParameter.USE_PLATFORM_CACHE == true && this.cachePartitionDelegate.isAvailable() == true) {
if (LoggerParameter.USE_PLATFORM_CACHE && this.cachePartitionDelegate.isAvailable()) {
// Platform cache does not support storing null values, so a predefined value is used as a substitute
if (value == null) {
value = PLATFORM_CACHE_NULL_VALUE;
Expand All @@ -232,7 +232,7 @@ public without sharing class LoggerCache {
public void remove(String key) {
this.transactionCache.remove(key);

if (LoggerParameter.USE_PLATFORM_CACHE == true && this.cachePartitionDelegate.isAvailable() == true) {
if (LoggerParameter.USE_PLATFORM_CACHE && this.cachePartitionDelegate.isAvailable()) {
this.cachePartitionDelegate.remove(key);
}
}
Expand Down
24 changes: 20 additions & 4 deletions nebula-logger/core/main/configuration/classes/LoggerParameter.cls
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ public class LoggerParameter {
private set;
}

/**
* @description Indicates if Nebula Logger will store the header values when logging an instance of `System.HttpResponse`.
* Controlled by the custom metadata record `LoggerParameter.StoreHttpResponseHeaderValues`, or `true` as the default.
* Regardless of how this parameter is configured, Nebula Logger will still log the header keys of any instance of
* `System.HttpResponse` that is logged - this parameter only controls if the header values are stored.
*/
public static final Boolean STORE_HTTP_RESPONSE_HEADER_VALUES {
get {
if (STORE_HTTP_RESPONSE_HEADER_VALUES == null) {
STORE_HTTP_RESPONSE_HEADER_VALUES = getBoolean('StoreHttpResponseHeaderValues', true);
}
return STORE_HTTP_RESPONSE_HEADER_VALUES;
}
private set;
}

/**
* @description The merge-field syntax to use when calling System.debug().
* Controlled by the custom metadata record `LoggerParameter.SystemDebugMessageFormat`, or `{OriginLocation__c}\n{Message__c}` as the default
Expand Down Expand Up @@ -631,7 +647,7 @@ public class LoggerParameter {
public static List<LoggerParameter__mdt> matchOnPrefix(String developerNamePrefix) {
List<LoggerParameter__mdt> matchingParameters = new List<LoggerParameter__mdt>();
for (String parameterDeveloperName : DEVELOPER_NAME_TO_RECORD.keySet()) {
if (parameterDeveloperName.startsWith(developerNamePrefix) == true) {
if (parameterDeveloperName.startsWith(developerNamePrefix)) {
matchingParameters.add(DEVELOPER_NAME_TO_RECORD.get(parameterDeveloperName));
}
}
Expand All @@ -640,13 +656,13 @@ public class LoggerParameter {

private static Map<String, LoggerParameter__mdt> loadRecords() {
Map<String, LoggerParameter__mdt> parameters = LoggerParameter__mdt.getAll().clone();
if (System.Test.isRunningTest() == true) {
if (System.Test.isRunningTest()) {
// Keep a copy of any records that *should* be loaded during tests
// Currently, only the record `SystemDebugMessageFormat` has a use case for this functionality,
// but others can be easily added if other use cases are found
Map<String, LoggerParameter__mdt> parametersToLoadDuringTests = new Map<String, LoggerParameter__mdt>();
for (String testContextParameterName : PARAMETERS_TO_LOAD_DURING_TESTS) {
if (parameters.containsKey(testContextParameterName) == true) {
if (parameters.containsKey(testContextParameterName)) {
parametersToLoadDuringTests.put(testContextParameterName, parameters.get(testContextParameterName));
}
}
Expand All @@ -658,7 +674,7 @@ public class LoggerParameter {

@TestVisible
private static void setMock(LoggerParameter__mdt parameter) {
if (String.isBlank(parameter.DeveloperName) == true) {
if (String.isBlank(parameter.DeveloperName)) {
throw new System.IllegalArgumentException('DeveloperName is required on `LoggerParameter__mdt: \n' + JSON.serializePretty(parameter));
}

Expand Down
Loading

0 comments on commit d1ed36e

Please sign in to comment.