Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
christiand93 committed Sep 20, 2024
1 parent 16dbf58 commit 732ab04
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/general-usage/04-custom-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ info("Test data", {"field": 42});

### SAP Cloud Logging

When using the library with SAP Cloud Logging custom fields get added as top-level fields.
When using the library with SAP Cloud Logging, custom fields get added as top-level fields.
Registering custom fields is not required in this case.

By default all custom field values get stringified, which can help to prevent field type mismatches when indexing to SAP Cloud Logging.
However, if you want to retain the original type of your custom fields you can change the type conversion configuration accordingly:
However, if you want to retain the original type of your custom fields, you can change the type conversion configuration accordingly:

```js
log.setCustomFieldsTypeConversion(CustomFieldsTypeConversion.Retain)
Expand Down
6 changes: 3 additions & 3 deletions src/lib/logger/recordFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export default class RecordFactory {
|| record.payload[key] != null || this.config.isSettable(key)) {
// Stringify, if conversion type 'stringify' is selected and value is not a string already.
if (customFieldsTypeConversion == CustomFieldsTypeConversion.Stringify && (typeof value) != "string") {
record.payload[key] = jsonStringifySafe(value);;
record.payload[key] = jsonStringifySafe(value);
} else {
record.payload[key] = value;
}
}
}

if ([CustomFieldsFormat.ApplicationLogging, CustomFieldsFormat.All].includes(customFieldsFormat)) {
Expand All @@ -131,7 +131,7 @@ export default class RecordFactory {
}
});

//writes custom fields in the correct order and correlates i to the place in registeredCustomFields
// Write custom fields in the correct order and correlates i to the place in registeredCustomFields
if (Object.keys(indexedCustomFields).length > 0) {
let res: any = {};
res.string = [];
Expand Down
2 changes: 1 addition & 1 deletion src/test/acceptance-test/custom-fields.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Test custom fields', function () {
log.logMessage("info", "test-message");
});

it('logs custom fields as strings', function () {
it('logs custom fields with their retained type', function () {
expect(lastOutput).to.have.property('field-a', 42).that.is.a('number');
expect(lastOutput).to.have.property('field-b', true).that.is.a('boolean');
expect(lastOutput).to.have.property('field-c').that.deep.equals({"key":"value"})
Expand Down

0 comments on commit 732ab04

Please sign in to comment.