Closed chanphiromsok closed 1 month ago
Same issue still.
Wrapping the content inside JSON.stringify
works.
logger.info(JSON.stringify(message, null, 2));
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
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";
}
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)),
...
};
In the patch method described above, the non-enumerable properties of an object (which is common when logging error objects) are not printed. This issue is resolved with a new stringify method in version 5.2.0.
@alessandro-bottamedi I'm trying 5.2.0, and it doesn't seems to fully work:
Logger.debug("NESTED OBJECT", {
nested: {
key: "value",
},
});
⬇️
LOG 2024-10-18T11:53:42.496Z | DEBUG : NESTED OBJECT
{
"nested": {}
}
Can you share your configuration?
Sure, here it is:
let fileLoggingStatus: "unitialized" | "enabled" | "disabled" = "unitialized";
const skippedLogsSet = new Set<Parameters<transportFunctionType>[0]>();
const Logger = logger.createLogger<"debug" | "info" | "warn" | "error">({
transport: (props) => {
if (__DEV__) {
consoleTransport(props);
}
switch (fileLoggingStatus) {
case "unitialized":
skippedLogsSet.add(props);
break;
case "enabled":
fileTransport(props);
break;
case "disabled":
break;
}
sentryTransport(props);
},
dateFormat: "iso",
});
There are some extra logic to initialize the file transport, but it shouldn't have any impact on this issue
Sorry, I found the bug, now with version 5.2.1 it should work correctly. Thanks for reporting it!
Great, thanks for your reactivity!
Since the version that fixed this issue (5.2.1) has been reverted, maybe we should reopen this issue? @alessandro-bottamedi
Since the version that fixed this issue (5.2.1) has been reverted, maybe we should reopen this issue? @alessandro-bottamedi
We didn’t roll back the entire version, only the config merge function. This issue is resolved in version v 5.2.2.
Oh okay, awesome! I should have tested before commenting, it indeed works fine! 😁
Same issue here, example output: