Problem
I'm using a custom implementation of a Logger which outputs all logs in the following format:
[current time] [function that invoked log()]: [log message]
My log function looks like this:
function formatCaller(caller: Function): string {
if (!caller) return '{?}:';
else return `{${caller.name}}: `;
}
export function log(...messages: unknown[]): void {
let caller = '{?}:';
try {
caller = formatCaller(log.caller);
} catch {}
const joinedMessage = messages.map((m) => (typeof m === 'string' ? m : JSON.stringify(m))).join(' ');
console.log(caller + joinedMessage);
}
On JSC (iOS) the caller name is correctly retrieved, but on Hermes log.caller evaluates to null because caller information is not available in Hermes bytecode. This makes it extremely difficult to trace breadcrumbs back when trying to find the source of an error that pops up in your Sentry/Crashlytics/...
Solution
Add [currentFunction].caller information. Since the function's code is stored as bytecode, I'm assuming only name and arguments are available properties, toString() should just return the name instead of the function's code.
Problem
I'm using a custom implementation of a Logger which outputs all logs in the following format:
My log function looks like this:
On JSC (iOS) the caller name is correctly retrieved, but on Hermes
log.callerevaluates to null because caller information is not available in Hermes bytecode. This makes it extremely difficult to trace breadcrumbs back when trying to find the source of an error that pops up in your Sentry/Crashlytics/...Solution
Add
[currentFunction].callerinformation. Since the function's code is stored as bytecode, I'm assuming onlynameandargumentsare available properties,toString()should just return thenameinstead of the function's code.