diff --git a/README.md b/README.md index 6461ee764..a4361884e 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,16 @@ Designed for Salesforce admins, developers & architects. A robust logger for Apex, Lightning Components, Flow, Process Builder & Integrations. -## Unlocked Package v4.6.11 +## Unlocked Package - v4.6.12 -[![Install Unlocked Package](./content/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015l2qQAA) -[![Install Unlocked Package](./content/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015l2qQAA) +[![Install Unlocked Package in a Sandbox](./content/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015l3oQAA) +[![Install Unlocked Package in Production](./content/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015l3oQAA) [![View Documentation](./content/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/) -## Managed Package v4.6.0 +## Managed Package - v4.6.0 -[![Install Managed Package](./content/btn-install-managed-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015keOQAQ) -[![Install Managed Package](./content/btn-install-managed-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015keOQAQ) +[![Install Managed Package in a Sandbox](./content/btn-install-managed-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015keOQAQ) +[![Install Managed Package in Production](./content/btn-install-managed-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015keOQAQ) [![View Milestone](./content/btn-view-managed-package-milestone.png)](https://github.com/jongpie/NebulaLogger/milestone/6) --- @@ -575,16 +575,6 @@ The Logger Console app provides access to the tabs for Logger's objects: `Log__c ![Logger Console app](./content/logger-console-app.png) -### Logger Admin Dashboard - -To help monitor logs in your org, the Logger Console app's homepage displays the included dashboard 'Logger Admin' - it displays several report charts to quickly see summary info about your logs. The dashboard supports filtering on: - -- Timestamp: based on `LogEntry__c.Timestamp__c` -- Logging Level: based on `LogEntry__c.LoggingLevel__c` -- Origin Type: based on `LogEntry__c.OriginType__c` - -![Logger Console Home](./content/logger-console-app-home.png) - ### Log's 'Manage' Quick Action To help development and support teams better manage logs (and any underlying code or config issues), some fields on `Log__c` are provided to track the owner, priority and status of a log. These fields are optional, but are helpful in critical environments (production, QA sandboxes, UAT sandboxes, etc.) for monitoring ongoing user activities. diff --git a/content/logger-console-app-home.png b/content/logger-console-app-home.png deleted file mode 100644 index 9149d26b6..000000000 Binary files a/content/logger-console-app-home.png and /dev/null differ diff --git a/managed-package/sfdx-project.json b/managed-package/sfdx-project.json index 439035232..a12fe4ea1 100644 --- a/managed-package/sfdx-project.json +++ b/managed-package/sfdx-project.json @@ -21,7 +21,7 @@ "Nebula Logger - Managed Package@4.0.0-9-managed-package-release": "04t5Y000000XJZ7QAO", "Nebula Logger - Managed Package@4.2.0-0-more-fields-and-methods": "04t5Y000000Xg4wQAC", "Nebula Logger - Managed Package@4.3.0-3-logger-console-app": "04t5Y000000YLDLQA4", - "Nebula Logger - Managed Package@4.4.0-2-config-default-save-method": "04t5Y0000027FFgQAM", + "Nebula Logger - Managed Package@4.4.0-2-configurable-default-save-method": "04t5Y0000027FFgQAM", "Nebula Logger - Managed Package@4.5.0-0-logger-plugin-framework": "04t5Y0000027FMhQAM", "Nebula Logger - Managed Package@4.6.0-0-tagging-system-overhaul": "04t5Y0000015keOQAQ" } diff --git a/nebula-logger-plugins/Logger-Admin-Dashboard/README.md b/nebula-logger-plugins/Logger-Admin-Dashboard/README.md new file mode 100644 index 000000000..209998516 --- /dev/null +++ b/nebula-logger-plugins/Logger-Admin-Dashboard/README.md @@ -0,0 +1,13 @@ +# Logger Admin Dashboard for Nebula Logger + +> :information_source: Requires Nebula Logger v4.6.12 or newer + +[![Install Unlocked Package Plugin](./content/btn-install-unlocked-package-plugin.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015l3yQAA) + +To help monitor logs in your org, this plugin includes a new Logger Admin dynamic dashboard, as well as several new reports. The dashboard displays several report charts to quickly see summary info about your logs. It supports filtering on: + +- Timestamp: based on `LogEntry__c.Timestamp__c` +- Logging Level: based on `LogEntry__c.LoggingLevel__c` +- Origin Type: based on `LogEntry__c.OriginType__c` + +![Logger Admin Dashboard](./content/logger-admin-dashboard.png) diff --git a/nebula-logger-plugins/Logger-Admin-Dashboard/content/btn-install-unlocked-package-plugin.png b/nebula-logger-plugins/Logger-Admin-Dashboard/content/btn-install-unlocked-package-plugin.png new file mode 100644 index 000000000..9c3bbf6a8 Binary files /dev/null and b/nebula-logger-plugins/Logger-Admin-Dashboard/content/btn-install-unlocked-package-plugin.png differ diff --git a/nebula-logger-plugins/Logger-Admin-Dashboard/content/logger-admin-dashboard.png b/nebula-logger-plugins/Logger-Admin-Dashboard/content/logger-admin-dashboard.png new file mode 100644 index 000000000..57d005540 Binary files /dev/null and b/nebula-logger-plugins/Logger-Admin-Dashboard/content/logger-admin-dashboard.png differ diff --git a/nebula-logger/main/log-management/dashboards/LogDashboards.dashboardFolder-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/dashboards/LogDashboards.dashboardFolder-meta.xml similarity index 100% rename from nebula-logger/main/log-management/dashboards/LogDashboards.dashboardFolder-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/dashboards/LogDashboards.dashboardFolder-meta.xml diff --git a/nebula-logger/main/log-management/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml similarity index 99% rename from nebula-logger/main/log-management/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml index d0904fcf6..e0d4d6f2f 100644 --- a/nebula-logger/main/log-management/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml +++ b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/dashboards/LogDashboards/LoggerAdmin.dashboard-meta.xml @@ -335,7 +335,6 @@ LoggedInUser true - test-jjw63tzh5qcz@example.com #000000 Logger Admin Dashboard #000000 diff --git a/nebula-logger/main/log-management/reports/LogReports/LogEntryDailyRetentionSummary.report-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryDailyRetentionSummary.report-meta.xml similarity index 100% rename from nebula-logger/main/log-management/reports/LogReports/LogEntryDailyRetentionSummary.report-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryDailyRetentionSummary.report-meta.xml diff --git a/nebula-logger/main/log-management/reports/LogReports/LogEntryDailySummary.report-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryDailySummary.report-meta.xml similarity index 100% rename from nebula-logger/main/log-management/reports/LogReports/LogEntryDailySummary.report-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryDailySummary.report-meta.xml diff --git a/nebula-logger/main/log-management/reports/LogReports/LogEntryOriginSummary.report-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryOriginSummary.report-meta.xml similarity index 100% rename from nebula-logger/main/log-management/reports/LogReports/LogEntryOriginSummary.report-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryOriginSummary.report-meta.xml diff --git a/nebula-logger/main/log-management/reports/LogReports/LogEntryScenarioSummary.report-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryScenarioSummary.report-meta.xml similarity index 100% rename from nebula-logger/main/log-management/reports/LogReports/LogEntryScenarioSummary.report-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntryScenarioSummary.report-meta.xml diff --git a/nebula-logger/main/log-management/reports/LogReports/LogEntrySummary.report-meta.xml b/nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntrySummary.report-meta.xml similarity index 100% rename from nebula-logger/main/log-management/reports/LogReports/LogEntrySummary.report-meta.xml rename to nebula-logger-plugins/Logger-Admin-Dashboard/plugin/reports/LogReports/LogEntrySummary.report-meta.xml diff --git a/nebula-logger/main/configuration/layouts/LogScenarioRule__mdt-Log Scenario Rule Layout.layout-meta.xml b/nebula-logger/main/configuration/layouts/LogScenarioRule__mdt-Log Scenario Rule Layout.layout-meta.xml new file mode 100644 index 000000000..65c8e9875 --- /dev/null +++ b/nebula-logger/main/configuration/layouts/LogScenarioRule__mdt-Log Scenario Rule Layout.layout-meta.xml @@ -0,0 +1,97 @@ + + + + false + true + true + + + + Required + MasterLabel + + + Required + DeveloperName + + + + + Edit + IsEnabled__c + + + + + + true + true + true + + + + Required + Scenario__c + + + + + Required + UserLoggingLevel__c + + + Edit + NumberOfDaysToRetainLogs__c + + + + + + false + true + true + + + + Required + NamespacePrefix + + + Readonly + CreatedById + + + + + Edit + IsProtected + + + Readonly + LastModifiedById + + + + + + true + true + false + + + + + + + false + false + false + false + false + + 00h17000007yeDt + 4 + 0 + Default + + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/LogScenarioRule__mdt.object-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/LogScenarioRule__mdt.object-meta.xml new file mode 100644 index 000000000..3c9a934f5 --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/LogScenarioRule__mdt.object-meta.xml @@ -0,0 +1,6 @@ + + + + Log Scenario Rules + Public + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/IsEnabled__c.field-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/IsEnabled__c.field-meta.xml new file mode 100644 index 000000000..7c3dca299 --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/IsEnabled__c.field-meta.xml @@ -0,0 +1,9 @@ + + + IsEnabled__c + true + false + SubscriberControlled + + Checkbox + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/NumberOfDaysToRetainLogs__c.field-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/NumberOfDaysToRetainLogs__c.field-meta.xml new file mode 100644 index 000000000..8ace31da7 --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/NumberOfDaysToRetainLogs__c.field-meta.xml @@ -0,0 +1,14 @@ + + + NumberOfDaysToRetainLogs__c + false + SubscriberControlled + This value is used to set the field Log__c.LogRetentionDate__c, which is then used by LogBatchPurger to delete old logs. To keep logs indefinitely, set this field to blank (null). + + 4 + false + 0 + Number + false + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/Scenario__c.field-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/Scenario__c.field-meta.xml new file mode 100644 index 000000000..ecfa752bd --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/Scenario__c.field-meta.xml @@ -0,0 +1,12 @@ + + + Scenario__c + false + false + SubscriberControlled + + 255 + true + Text + true + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/UserLoggingLevel__c.field-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/UserLoggingLevel__c.field-meta.xml new file mode 100644 index 000000000..5f2ee15fd --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/fields/UserLoggingLevel__c.field-meta.xml @@ -0,0 +1,52 @@ + + + UserLoggingLevel__c + false + SubscriberControlled + Overrides the user's logging level (normally controlled via LoggerSettings__c.LoggingLevel__c) for any transactions with the specified Scenario + + true + Picklist + + true + + false + + ERROR + false + + + + WARN + false + + + + INFO + false + + + + DEBUG + false + + + + FINE + false + + + + FINER + false + + + + FINEST + false + + + + + diff --git a/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/listViews/All.listView-meta.xml b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/listViews/All.listView-meta.xml new file mode 100644 index 000000000..392e9ef02 --- /dev/null +++ b/nebula-logger/main/configuration/objects/LogScenarioRule__mdt/listViews/All.listView-meta.xml @@ -0,0 +1,12 @@ + + + All + MasterLabel + DeveloperName + IsEnabled__c + Scenario__c + UserLoggingLevel__c + NumberOfDaysToRetainLogs__c + Everything + + diff --git a/nebula-logger/main/configuration/objects/LoggerSettings__c/fields/DefaultNumberOfDaysToRetainLogs__c.field-meta.xml b/nebula-logger/main/configuration/objects/LoggerSettings__c/fields/DefaultNumberOfDaysToRetainLogs__c.field-meta.xml index ad559b4fd..0fd05dfdf 100644 --- a/nebula-logger/main/configuration/objects/LoggerSettings__c/fields/DefaultNumberOfDaysToRetainLogs__c.field-meta.xml +++ b/nebula-logger/main/configuration/objects/LoggerSettings__c/fields/DefaultNumberOfDaysToRetainLogs__c.field-meta.xml @@ -8,7 +8,7 @@ This value is used to set the field Log__c.LogRetentionDate__c, which is then used by LogBatchPurger to delete old logs. To keep logs indefinitely, set this field to blank (null). - 3 + 4 false 0 false diff --git a/nebula-logger/main/log-management/applications/LoggerConsole.app-meta.xml b/nebula-logger/main/log-management/applications/LoggerConsole.app-meta.xml index 6fe0112ef..d99ae8e55 100644 --- a/nebula-logger/main/log-management/applications/LoggerConsole.app-meta.xml +++ b/nebula-logger/main/log-management/applications/LoggerConsole.app-meta.xml @@ -1,13 +1,5 @@ - - Tab - LoggerConsoleHomePage - Large - false - Flexipage - standard-home - #1E1E1E true @@ -19,7 +11,6 @@ false Console - standard-home Log__c LogEntry__c LogEntryTag__c @@ -50,9 +41,6 @@ standard-Dashboard - - standard-home - standard-report diff --git a/nebula-logger/main/log-management/classes/LogHandler.cls b/nebula-logger/main/log-management/classes/LogHandler.cls index 6c97becd8..4aeeb7429 100644 --- a/nebula-logger/main/log-management/classes/LogHandler.cls +++ b/nebula-logger/main/log-management/classes/LogHandler.cls @@ -9,7 +9,9 @@ */ public without sharing class LogHandler extends LoggerSObjectHandler { @TestVisible - private static Map logStatusByName = loadActiveLogStatuses(); + private static final Map LOG_STATUS_NAME_TO_STATUS = loadActiveLogStatuses(); + @TestVisible + private static final Map SCENARIO_TO_MOCK_SCENARIO_RULE = new Map(); @TestVisible private List logs; @@ -17,14 +19,13 @@ public without sharing class LogHandler extends LoggerSObjectHandler { private Map oldLogsById; private static Map loadActiveLogStatuses() { - Map logStatusByName = new Map(); + Map logStatusNameToStatus = new Map(); for (LogStatus__mdt logStatus : LogStatus__mdt.getAll().values()) { if (logStatus.IsActive__c == true) { - logStatusByName.put(logStatus.MasterLabel, logStatus); + logStatusNameToStatus.put(logStatus.MasterLabel, logStatus); } } - - return logStatusByName; + return logStatusNameToStatus; } /** @@ -61,7 +62,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { private void setClosedStatusFields() { for (Log__c log : this.logs) { // Determine if the status is considered closed (based on `LogStatus__mdt` custom metadata) - LogStatus__mdt logStatus = logStatusByName.get(log.Status__c); + LogStatus__mdt logStatus = LOG_STATUS_NAME_TO_STATUS.get(log.Status__c); if (logStatus != null) { log.IsClosed__c = logStatus.IsClosed__c; log.IsResolved__c = logStatus.IsResolved__c; @@ -79,6 +80,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { } private void setLogRetentionDate() { + Map scenarioToScenarioRule = queryScenarioRules(this.logs); for (Log__c log : this.logs) { // If the retention date has already been populated, leave it as-is if (log.LogRetentionDate__c != null) { @@ -88,9 +90,18 @@ public without sharing class LogHandler extends LoggerSObjectHandler { // Load the logging user's settings User loggingUser = new User(Id = log.LoggedBy__c, ProfileId = log.ProfileId__c); LoggerSettings__c loggingUserSettings = Logger.getUserSettings(loggingUser); - Integer daysToRetainLog = Integer.valueOf(loggingUserSettings.DefaultNumberOfDaysToRetainLogs__c); - // When loggerSettings.DefaultNumberOfDaysToRetainLogs__c is null, assume that the log should be kept forever, + // Load the configured scenario rule (if one exists) + LogScenarioRule__mdt matchingScenarioRule = scenarioToScenarioRule.get(log.Scenario__c); + if (Test.isRunningTest() == true) { + matchingScenarioRule = SCENARIO_TO_MOCK_SCENARIO_RULE.get(log.Scenario__c); + } + + Integer daysToRetainLog = Integer.valueOf( + matchingScenarioRule != null ? matchingScenarioRule.NumberOfDaysToRetainLogs__c : loggingUserSettings.DefaultNumberOfDaysToRetainLogs__c + ); + + // When daysToRetainLog is null, assume that the log should be kept forever, // and set the retention date to null so that LogBatchPurger filters out/ignores the record log.LogRetentionDate__c = daysToRetainLog == null ? null : System.today().addDays(daysToRetainLog); } @@ -145,4 +156,28 @@ public without sharing class LogHandler extends LoggerSObjectHandler { } Database.insert(logShares, false); } + + private static Map queryScenarioRules(List logs) { + List scenarios = new List(); + for (Log__c log : logs) { + if (log.Scenario__c != null) { + scenarios.add(log.Scenario__c); + } + } + + Map scenarioToScenarioRule = new Map(); + for (LogScenarioRule__mdt scenarioRule : [ + SELECT Scenario__c, NumberOfDaysToRetainLogs__c + FROM LogScenarioRule__mdt + WHERE IsEnabled__c = TRUE AND Scenario__c IN :scenarios + ]) { + scenarioToScenarioRule.put(scenarioRule.Scenario__c, scenarioRule); + } + return scenarioToScenarioRule; + } + + @TestVisible + private static void setMockScenarioRule(LogScenarioRule__mdt scenarioRule) { + SCENARIO_TO_MOCK_SCENARIO_RULE.put(scenarioRule.Scenario__c, scenarioRule); + } } diff --git a/nebula-logger/main/log-management/flexipages/LoggerConsoleHomePage.flexipage-meta.xml b/nebula-logger/main/log-management/flexipages/LoggerConsoleHomePage.flexipage-meta.xml deleted file mode 100644 index 5ee9ce4ec..000000000 --- a/nebula-logger/main/log-management/flexipages/LoggerConsoleHomePage.flexipage-meta.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - dashboardName - LoggerAdmin - - - hideOnError - false - - desktopDashboards:embeddedDashboard - - - main - Region - - Logger Console Home Page - - HomePage - diff --git a/nebula-logger/main/logger-engine/classes/Logger.cls b/nebula-logger/main/logger-engine/classes/Logger.cls index 63aea91a6..a917f80dc 100644 --- a/nebula-logger/main/logger-engine/classes/Logger.cls +++ b/nebula-logger/main/logger-engine/classes/Logger.cls @@ -13,9 +13,11 @@ 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.6.11'; + private static final String CURRENT_VERSION_NUMBER = 'v4.6.12'; private static final LoggingLevel DEFAULT_LOGGING_LEVEL = LoggingLevel.DEBUG; private static final List LOG_ENTRIES_BUFFER = new List(); + @TestVisible + private static final Map SCENARIO_TO_MOCK_SCENARIO_RULE = new Map(); private static final String TRANSACTION_ID = setTransactionId(); private static final Quiddity TRANSACTION_QUIDDITY = setTransactionQuiddity(); @@ -2451,8 +2453,27 @@ global with sharing class Logger { * and `Log__c.Scenario__c`, and can be used to filter & group logs * @param scenario The name to use for the current transaction's scenario */ - public static void setScenario(String scenario) { + global static void setScenario(String scenario) { transactionScenario = scenario; + + // LogScenarioRule__mdt scenarioRule = LogScenarioRule__mdt.getInstance(scenario); + LogScenarioRule__mdt matchingScenarioRule; + for (LogScenarioRule__mdt scenarioRule : [SELECT UserLoggingLevel__c FROM LogScenarioRule__mdt WHERE IsEnabled__c = TRUE AND Scenario__c = :scenario]) { + matchingScenarioRule = scenarioRule; + } + + if (Test.isRunningTest() == true) { + matchingScenarioRule = SCENARIO_TO_MOCK_SCENARIO_RULE.get(scenario); + } + + if (matchingScenarioRule != null) { + getUserSettings().LoggingLevel__c = matchingScenarioRule.UserLoggingLevel__c; + } + } + + @TestVisible + private static void setMockScenarioRule(LogScenarioRule__mdt scenarioRule) { + SCENARIO_TO_MOCK_SCENARIO_RULE.put(scenarioRule.Scenario__c, scenarioRule); } /** diff --git a/nebula-logger/main/plugin-framework/layouts/LoggerPlugin__mdt-Logger Plugin Layout.layout-meta.xml b/nebula-logger/main/plugin-framework/layouts/LoggerPlugin__mdt-Logger Plugin Layout.layout-meta.xml index 8468be468..3f2bf15a1 100644 --- a/nebula-logger/main/plugin-framework/layouts/LoggerPlugin__mdt-Logger Plugin Layout.layout-meta.xml +++ b/nebula-logger/main/plugin-framework/layouts/LoggerPlugin__mdt-Logger Plugin Layout.layout-meta.xml @@ -10,13 +10,17 @@ Required MasterLabel - - Required DeveloperName + + + Edit + IsEnabled__c + + @@ -29,6 +33,10 @@ Required SObjectType__c + + Edit + ExecutionOrder__c + @@ -42,6 +50,19 @@ + + true + false + false + + + + Edit + Description__c + + + + false true @@ -85,7 +106,7 @@ false false - 00h1F000005MrCO + 00h17000007ebex 4 0 Default diff --git a/nebula-logger/main/plugin-framework/objects/LoggerPlugin__mdt/listViews/All.listView-meta.xml b/nebula-logger/main/plugin-framework/objects/LoggerPlugin__mdt/listViews/All.listView-meta.xml index 885a3c636..eaa65e95c 100644 --- a/nebula-logger/main/plugin-framework/objects/LoggerPlugin__mdt/listViews/All.listView-meta.xml +++ b/nebula-logger/main/plugin-framework/objects/LoggerPlugin__mdt/listViews/All.listView-meta.xml @@ -4,10 +4,10 @@ MasterLabel DeveloperName IsEnabled__c + ExecutionOrder__c SObjectType__c PluginType__c PluginApiName__c - ExecutionOrder__c Description__c Everything diff --git a/nebula-logger/tests/log-management/classes/LogHandler_Tests.cls b/nebula-logger/tests/log-management/classes/LogHandler_Tests.cls index 1c6852701..efe4d7cf1 100644 --- a/nebula-logger/tests/log-management/classes/LogHandler_Tests.cls +++ b/nebula-logger/tests/log-management/classes/LogHandler_Tests.cls @@ -40,7 +40,7 @@ private class LogHandler_Tests { LogStatus__mdt closedStatus = new LogStatus__mdt(IsActive__c = true, MasterLabel = SECOND_STATUS, IsClosed__c = true, IsResolved__c = true); logStatusByName.put(closedStatus.MasterLabel, closedStatus); - LogHandler.logStatusByName = logStatusByName; + LogHandler.LOG_STATUS_NAME_TO_STATUS.putAll(logStatusByName); } @IsTest @@ -116,25 +116,37 @@ private class LogHandler_Tests { } @IsTest - static void it_should_set_retention_date_when_configured() { + static void it_should_set_retention_date_when_configured_via_logger_settings() { Integer daysToRetainLog = 90; Date expectedRetentionDate = System.today().addDays(daysToRetainLog); - - LoggerSettings__c settings = Logger.getUserSettings(); - settings.DefaultNumberOfDaysToRetainLogs__c = daysToRetainLog; - upsert settings; - - Test.startTest(); + Logger.getUserSettings().DefaultNumberOfDaysToRetainLogs__c = daysToRetainLog; + upsert Logger.getUserSettings(); Log__c log = new Log__c(LoggedBy__c = UserInfo.getUserId(), TransactionId__c = '1234'); insert log; - Test.stopTest(); - log = [SELECT Id, LogRetentionDate__c FROM Log__c WHERE Id = :log.Id]; System.assertEquals(expectedRetentionDate, log.LogRetentionDate__c); } + @IsTest + static void it_should_set_retention_date_when_configured_via_scenario_rules() { + Integer defaultDaysToRetainLog = 1; + Integer daysToRetainLog = 90; + Date expectedRetentionDate = System.today().addDays(daysToRetainLog); + Logger.getUserSettings().DefaultNumberOfDaysToRetainLogs__c = defaultDaysToRetainLog; + upsert Logger.getUserSettings(); + String transactionScenarioName = 'some scenario'; + LogScenarioRule__mdt scenarioRule = new LogScenarioRule__mdt(Scenario__c = transactionScenarioName, NumberOfDaysToRetainLogs__c = daysToRetainLog); + LogHandler.setMockScenarioRule(scenarioRule); + + Log__c log = new Log__c(LoggedBy__c = UserInfo.getUserId(), Scenario__c = transactionScenarioName, TransactionId__c = '1234'); + insert log; + + log = [SELECT Id, Scenario__c, LogRetentionDate__c FROM Log__c WHERE Id = :log.Id]; + System.assertEquals(expectedRetentionDate, log.LogRetentionDate__c); + } + @IsTest static void it_should_have_null_retention_date_when_no_retention_configured() { LoggerSettings__c settings = Logger.getUserSettings(); diff --git a/nebula-logger/tests/logger-engine/classes/Logger_Tests.cls b/nebula-logger/tests/logger-engine/classes/Logger_Tests.cls index ddbc71edc..42635608e 100644 --- a/nebula-logger/tests/logger-engine/classes/Logger_Tests.cls +++ b/nebula-logger/tests/logger-engine/classes/Logger_Tests.cls @@ -340,6 +340,30 @@ private class Logger_Tests { System.assertEquals(transactionScenarioName, log.Scenario__c, 'Scenario__c was not properly set on the Log__c record'); } + @IsTest + static void it_should_set_scenario_and_apply_scenario_rule_logging_level() { + String transactionId = Logger.getTransactionId(); + String transactionScenarioName = 'some test scenario for this transaction'; + LogScenarioRule__mdt scenarioRule = new LogScenarioRule__mdt(Scenario__c = transactionScenarioName, UserLoggingLevel__c = LoggingLevel.FINER.name()); + Logger.setMockScenarioRule(scenarioRule); + Logger.getUserSettings().LoggingLevel__c = LoggingLevel.ERROR.name(); + System.assertNotEquals(Logger.getUserSettings().LoggingLevel__c, scenarioRule.UserLoggingLevel__c); + + Logger.setScenario(transactionScenarioName); + for (Integer i = 0; i < 5; i++) { + Logger.finer('my log entry'); + } + Logger.saveLog(); + Test.getEventBus().deliver(); + + Log__c log = [SELECT Id, Scenario__c FROM Log__c WHERE TransactionId__c = :transactionId]; + System.assertEquals(transactionScenarioName, log.Scenario__c, 'Scenario__c was not properly set on the Log__c record'); + List logEntries = [SELECT Id, LoggingLevel__c FROM LogEntry__c WHERE Log__c = :log.Id]; + for (LogEntry__c logEntry : logEntries) { + System.assertEquals(LoggingLevel.FINER.name(), logEntry.LoggingLevel__c, 'All log entries should have FINER as the logging level'); + } + } + @IsTest static void it_should_use_last_scenario_when_multiple_scenarios_specified() { String transactionId = Logger.getTransactionId(); diff --git a/package.json b/package.json index d609a4da3..cce23ea05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nebula-logger", - "version": "4.6.11", + "version": "4.6.12", "description": "Designed for Salesforce admins, developers & architects. A robust logger for Apex, Flow, Process Builder & Integrations.", "author": "Jonathan Gillespie", "license": "MIT", @@ -49,6 +49,8 @@ "package:version:number:fix": "pwsh ./scripts/build/sync-package-version-number.ps1", "package:version:number:verify": "pwsh scripts/build/validate-current-package-version-number.ps1", "permset:assign:admin": "sfdx force:user:permset:assign --permsetname LoggerAdmin", + "plugin:version:create:log-retention-rules": "sfdx force:package:version:create --json --package \"Nebula Logger Plugin - Log Retention Rules\" --codecoverage --installationkeybypass --wait 30", + "plugin:version:create:logger-admin-dashboard": "sfdx force:package:version:create --json --package \"Nebula Logger Plugin - Logger Admin Dashboard\" --codecoverage --installationkeybypass --wait 30", "plugin:version:create:slack": "sfdx force:package:version:create --json --package \"Nebula Logger Plugin - Slack\" --codecoverage --installationkeybypass --wait 30", "prepare": "husky install && chmod +x ./.husky/pre-commit && sfdx plugins:link ./node_modules/@salesforce/sfdx-scanner", "prettier:fix": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"", diff --git a/scripts/build/sync-package-version-number.ps1 b/scripts/build/sync-package-version-number.ps1 index 53ca4fde8..60da815d9 100644 --- a/scripts/build/sync-package-version-number.ps1 +++ b/scripts/build/sync-package-version-number.ps1 @@ -29,7 +29,6 @@ function Update-Package-JSON { Write-Output "Bumping package.json version number to: $versionNumber" $packageJson.version = $versionNumber - ConvertTo-Json -InputObject $packageJson | Set-Content -Path $packageJsonPath -NoNewline prettier --write $packageJsonPath git add $packageJsonPath @@ -45,13 +44,11 @@ function Update-README { ) $versionNumber = "v" + $versionNumber $readmeContents = Get-README - # Write-Output "$readmeContents" Write-Output "Bumping README unlocked package version number to: $versionNumber" - $targetRegEx = "(.+Unlocked Package')(.+)" - $replacementRegEx = '$1' + $versionNumber + '$3' + $targetRegEx = "(.+ Unlocked Package - )(.+)" + $replacementRegEx = '$1' + $versionNumber $readmeContents -replace $targetRegEx, $replacementRegEx | Set-Content -Path $readmeClassPath -NoNewline - Write-Output "$readmeContents" prettier --write $readmeClassPath git add $readmeClassPath } @@ -68,7 +65,6 @@ function Update-Logger-Class { $loggerClassContents = Get-Logger-Class Write-Output "Bumping Logger.cls version number to: $versionNumber" - $targetRegEx = "(.+CURRENT_VERSION_NUMBER = ')(.+)(';)" $replacementRegEx = '$1' + $versionNumber + '$3' $loggerClassContents -replace $targetRegEx, $replacementRegEx | Set-Content -Path $loggerClassPath -NoNewline @@ -80,5 +76,5 @@ $versionNumber = Get-Version-Number Write-Output "Target Version Number: $versionNumber" Update-Package-JSON $versionNumber -# Update-README $versionNumber TODO: fix this +Update-README $versionNumber Update-Logger-Class $versionNumber diff --git a/sfdx-project.json b/sfdx-project.json index a66128486..c570aa635 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -8,11 +8,24 @@ "path": "nebula-logger", "default": false, "definitionFile": "config/project-scratch-def-with-experience-cloud.json", - "versionNumber": "4.6.11.0", - "versionName": "Admin enhancements - new dashboard, reports, and error email alerts", - "versionDescription": "Added new Logger Console homepage to display the new Logger Admin dashboard, added Logger error email notifications", + "versionNumber": "4.6.12.0", + "versionName": "Log Scenario Rules", + "versionDescription": "Added new CMDT LogScenarioRule__mdt to configure scenario-specific logging levels and retention dates", "releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases" }, + { + "package": "Nebula Logger Plugin - Logger Admin Dashboard", + "path": "nebula-logger-plugins/Logger-Admin-Dashboard/plugin", + "dependencies": [ + { + "package": "Nebula Logger - Unlocked Package@4.6.12-0-log-scenario-rules" + } + ], + "versionName": "Beta Release", + "versionNumber": "0.9.0.0", + "versionDescription": "Initial beta version of new dashboard plugin", + "default": false + }, { "package": "Nebula Logger Plugin - Slack", "path": "nebula-logger-plugins/Slack", @@ -46,6 +59,7 @@ "Nebula Logger - Unlocked Package@4.6.1-0-summer-21-upgrade": "04t5Y0000015kfMQAQ", "Nebula Logger - Unlocked Package@4.6.10-0-new-log-and-logger-settings-fields": "04t5Y0000015l27QAA", "Nebula Logger - Unlocked Package@4.6.11-0-admin-enhancements---new-dashboard,-reports,-and-error-email-alerts": "04t5Y0000015l2qQAA", + "Nebula Logger - Unlocked Package@4.6.12-0-log-scenario-rules": "04t5Y0000015l3oQAA", "Nebula Logger - Unlocked Package@4.6.2-0-anonymous-logs": "04t5Y0000015kgPQAQ", "Nebula Logger - Unlocked Package@4.6.3-0-more-metadata-data": "04t5Y0000015kgeQAA", "Nebula Logger - Unlocked Package@4.6.4-0-logger-for-lwc-and-aura": "04t5Y0000015kgjQAA", @@ -54,6 +68,9 @@ "Nebula Logger - Unlocked Package@4.6.7-0-security-enhancements": "04t5Y0000015klZQAQ", "Nebula Logger - Unlocked Package@4.6.8-0-new-log-entry-event-stream-component": "04t5Y0000015kplQAA", "Nebula Logger - Unlocked Package@4.6.9-0-custom-metadata-types-optimized": "04t5Y0000015kqtQAA", + "Nebula Logger Plugin - Log Retention Rules": "0Ho5Y000000blNfSAI", + "Nebula Logger Plugin - Logger Admin Dashboard": "0Ho5Y000000blNkSAI", + "Nebula Logger Plugin - Logger Admin Dashboard@0.9.0-0": "04t5Y0000015l3yQAA", "Nebula Logger Plugin - Slack": "0Ho5Y000000blMDSAY", "Nebula Logger Plugin - Slack@0.9.0-0-beta-release": "04t5e00000061lHAAQ", "Nebula Logger Plugin - Slack@0.9.1-0-beta-release-round-2": "04t5e00000065xiAAA",