From 890f2f92dee17f10f582f60132fda9bfbdd8af7c Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Tue, 10 Sep 2024 00:43:47 -0400 Subject: [PATCH] [WIP] --- .../logger-engine/classes/CallableLogger.cls | 5 ++++- .../classes/CallableLogger_Tests.cls | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nebula-logger/core/main/logger-engine/classes/CallableLogger.cls b/nebula-logger/core/main/logger-engine/classes/CallableLogger.cls index 20cf6380b..dbe1a0405 100644 --- a/nebula-logger/core/main/logger-engine/classes/CallableLogger.cls +++ b/nebula-logger/core/main/logger-engine/classes/CallableLogger.cls @@ -84,7 +84,10 @@ global without sharing class CallableLogger implements System.Callable { } private LogEntryEventBuilder newEntry(Map arguments) { - System.LoggingLevel loggingLevel = (System.LoggingLevel) arguments.get(ARGUMENT_LOGGING_LEVEL); + // The value of loggingLevel could be either a string name or enum value, + // so coerce it to a string for consistency + String loggingLevelName = '' + arguments.get(ARGUMENT_LOGGING_LEVEL); + System.LoggingLevel loggingLevel = Logger.getLoggingLevel(loggingLevelName); String message = (String) arguments.get(ARGUMENT_MESSAGE); LogEntryEventBuilder logEntryEventBuilder = Logger.newEntry(loggingLevel, message); diff --git a/nebula-logger/core/tests/logger-engine/classes/CallableLogger_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/CallableLogger_Tests.cls index 67b95a14f..635d6a068 100644 --- a/nebula-logger/core/tests/logger-engine/classes/CallableLogger_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/CallableLogger_Tests.cls @@ -98,7 +98,7 @@ private class CallableLogger_Tests { } @IsTest - static void it_adds_new_entry() { + static void it_adds_new_entry_using_logging_level_enum() { System.LoggingLevel loggingLevel = System.LoggingLevel.FINE; String message = 'some log entry message'; @@ -112,6 +112,21 @@ private class CallableLogger_Tests { System.Assert.areEqual(message, logEntryEvent.Message__c); } + @IsTest + static void it_adds_new_entry_using_logging_level_name() { + String loggingLevelName = System.LoggingLevel.FINE.name(); + String message = 'some log entry message'; + + System.Callable callableLoggerInstance = (System.Callable) System.Type.forName('CallableLogger').newInstance(); + Object returnedValue = callableLoggerInstance.call('newEntry', new Map{ 'loggingLevel' => loggingLevelName, 'message' => message }); + + System.Assert.isNotNull(returnedValue); + System.Assert.isInstanceOfType(returnedValue, LogEntryEventBuilder.class); + LogEntryEvent__e logEntryEvent = ((LogEntryEventBuilder) returnedValue).getLogEntryEvent(); + System.Assert.areEqual(loggingLevelName, logEntryEvent.LoggingLevel__c); + System.Assert.areEqual(message, logEntryEvent.Message__c); + } + @IsTest static void it_adds_new_entry_with_exception() { System.LoggingLevel loggingLevel = System.LoggingLevel.FINE;