Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Sep 12, 2024
1 parent c7dee4b commit 86b56a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 7 additions & 5 deletions nebula-logger/core/main/logger-engine/classes/CallableLogger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
global without sharing class CallableLogger implements System.Callable {
// Names of arguments used for both input & output (depending on which action is called)
private static final String ARGUMENT_EXCEPTION = 'exception';
private static final String ARGUMENT_LOG_ENTRY_EVENT_BUILDER = 'logEntryEventBuilder';
private static final String ARGUMENT_LOGGING_LEVEL = 'loggingLevel';
private static final String ARGUMENT_MESSAGE = 'message';
private static final String ARGUMENT_PARENT_LOG_TRANSACTION_ID = 'parentLogTransactionId';
Expand Down Expand Up @@ -42,8 +43,9 @@ global without sharing class CallableLogger implements System.Callable {
* @return The value returned by the `Logger` method called as an `Object` instance, or `null` if the method being called does not have a return value
*/
global Object call(String action, Map<String, Object> arguments) {
arguments = arguments ?? new Map<String, Object>();
LoggerStackTrace.ignoreOrigin(CallableLogger.class);

arguments = arguments ?? new Map<String, Object>();
Map<String, Object> input = (Map<String, Object>) arguments.get(OMNISTUDIO_ARGUMENT_INPUT) ?? arguments;
Map<String, Object> output = (Map<String, Object>) arguments.get(OMNISTUDIO_ARGUMENT_OUTPUT) ?? new Map<String, Object>();

Expand Down Expand Up @@ -85,20 +87,18 @@ global without sharing class CallableLogger implements System.Callable {
}
// Methods for adding & saving log entries
when 'newEntry' {
this.newEntry(input);
output.put(OUTPUT_ARGUMENT_CALL_IS_SUCCESS, true);
output.put(ARGUMENT_LOG_ENTRY_EVENT_BUILDER, this.newEntry(input));
}
when 'saveLog' {
this.saveLog(input);
output.put(OUTPUT_ARGUMENT_CALL_IS_SUCCESS, true);
}
when else {
throw new System.IllegalArgumentException('Unknown action: ' + action);
}
}
}

private void newEntry(Map<String, Object> input) {
private LogEntryEventBuilder newEntry(Map<String, Object> input) {
// The value of loggingLevel could be either a string name or an enum value from System.LoggingLevel,
// so always first convert it to a string for consistency
String loggingLevelName = input.get(ARGUMENT_LOGGING_LEVEL)?.toString();
Expand All @@ -125,6 +125,8 @@ global without sharing class CallableLogger implements System.Callable {
if (input.containsKey(ARGUMENT_TAGS)) {
logEntryEventBuilder.addTags((List<String>) input.get(ARGUMENT_TAGS));
}

return logEntryEventBuilder;
}

private void saveLog(Map<String, Object> input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,19 @@ private class CallableLogger_Tests {
}

@IsTest
static void it_adds_new_entry_using_logging_level_enum() {
static void it_adds_new_entry_using_standard_approach() {
System.LoggingLevel loggingLevel = System.LoggingLevel.FINE;
String message = 'some log entry message';

System.Callable callableLoggerInstance = (System.Callable) System.Type.forName('CallableLogger').newInstance();
Object returnedValue = callableLoggerInstance.call('newEntry', new Map<String, Object>{ 'loggingLevel' => loggingLevel, 'message' => message });
Map<String, Object> returnedOutput = (Map<String, Object>) callableLoggerInstance.call(
'newEntry',
new Map<String, Object>{ 'loggingLevel' => loggingLevel, 'message' => message }
);

System.Assert.isNotNull(returnedValue);
System.Assert.isInstanceOfType(returnedValue, LogEntryEventBuilder.class);
LogEntryEvent__e logEntryEvent = ((LogEntryEventBuilder) returnedValue).getLogEntryEvent();
System.Assert.areEqual(2, returnedOutput.size());
System.Assert.areEqual(true, returnedOutput.get('isSuccess'), 'Expected isSuccess == true. Output received: ' + returnedOutput);
LogEntryEvent__e logEntryEvent = ((LogEntryEventBuilder) returnedOutput.get('logEntryEventBuilder')).getLogEntryEvent();
System.Assert.areEqual(loggingLevel.name(), logEntryEvent.LoggingLevel__c);
System.Assert.areEqual(message, logEntryEvent.Message__c);
}
Expand Down

0 comments on commit 86b56a5

Please sign in to comment.