Good Code
The good version emits structured JSON with stable fields that log systems can search and aggregate.
Lesson 09
Log machine-readable events with request context and without sensitive data.
type LogEvent = {
level: "info" | "error";
message: string;
requestId: string;
durationMs?: number;
};
export function logEvent(event: LogEvent) {
console.log(JSON.stringify({
time: new Date().toISOString(),
...event,
}));
}export function logLoginAttempt(email: string, password: string) {
console.log("Login failed for " + email + " with password " + password);
}The good version emits structured JSON with stable fields that log systems can search and aggregate.
The bad version logs a free-form string and includes a password, turning logs into a security incident.