Production services should log structured data (JSON) rather than free-form strings, with a level (`debug`, `info`, `warn`, `error`) so logs can be filtered, aggregated and alerted on by log-management tools.
js
function log(level, message, meta = {}) {
console.log(JSON.stringify({ level, message, time: new Date().toISOString(), ...meta }));
}
log("info", "server started", { port: 3000 });
log("error", "rpc call failed", { method: "eth_getBalance", error: "timeout" });Good logging includes context (request ids, user/address, timing) without leaking secrets (private keys, tokens, passwords) — a common and costly mistake is logging an entire request body that happens to contain sensitive data.