Meaningful logs
1/14/2023 • about 1 min read
Production logs are important.
When a production issue occurs, the logs that provide extra meaningful info would make the investigation much more efficient.
// I did this before
console.log("result", result);
// I did this too
console.log("👉 Accounts: ", JSON.stringify(result, null, 2));
// or
console.log("🔴 Error: ", error);
// Now I find this might be better
console.log(
`👉 Getting account ${accountId}'s info: `,
JSON.stringify(result, null, 2)
);
console.error(`🔴 Failed getting account ${accountId}'s info: `, error);
// Limit the logs when the data is sensitive; logs might get hacked
console.log(`👉 Getting account ${accountId}'s info...`);
// ...
console.log(`✅ Done getting account ${accountId}'s info.`);