nested object does not show
chanphiromsok opened this issue · 6 comments
chanphiromsok commented
nested object does not show
schmidal commented
Same issue here, example output:
LOG 13:35:15 | DEBUG : myAsyncNotificationReceivedHandler - Push Notification Content:
{
"body": "Test",
"data": {}, // **IN FACT, DATA DOES CONTAIN ELEMENTS**
"title": "Title",
"deeplinkUrl": "myapp://"
}
GninninwokyOuattara commented
GninninwokyOuattara commented
callaars commented
I think this is done because otherwise the logs might be getting ridiculously long. You can patch it though if you want in src/index.ts:53
Norcy commented
same issue.
Thanks to @callaars
This patch code works for me
diff --git a/node_modules/react-native-logs/src/index.ts b/node_modules/react-native-logs/src/index.ts
index 8b82148..0fc7c35 100644
--- a/node_modules/react-native-logs/src/index.ts
+++ b/node_modules/react-native-logs/src/index.ts
@@ -50,7 +50,7 @@ let stringifyFunc = (msg: any): string => {
} else {
try {
stringMsg =
- "\n" + JSON.stringify(msg, Object.getOwnPropertyNames(msg), 2) + "\n";
+ "\n" + JSON.stringify(msg, null, 2) + "\n";
} catch (error) {
stringMsg += "Undefined Message";
}
MJRT commented
it don't need patch, just custom a stringify, use this cover more cases:
export function objectsReplacer(_key: string, value: any): any {
if (typeof value in ['undefined', 'symbol']) {
return undefined;
} else if (typeof value === 'bigint') {
return value.toString();
} else if (value instanceof Map) {
return Array.from(value.entries());
} else if (value instanceof Set) {
return Array.from(value.values());
}
return value;
}
const logConfig: configLoggerType = {
...
stringifyFunc: ((msg) => JSON.stringify(msg, objectsReplacer, 2)),
...
};