Structured logging records diagnostic events in consistently formatted fields so they can be analyzed. In a frontend production workflow, logs are one source of evidence for detecting and diagnosing issues, alongside monitoring and client-side error tracking. section 5.4
Interview scenario
Asked how you address a production issue? Explain how you would use telemetry and logs to triage it, reproduce it in a test environment, and verify a targeted fix with automated tests. Document the root cause, then add a regression test or observability hook to help catch recurrence. section 5.4
Listing 5.15 Unit test with a mocked logger
import { formatDate } from '../utils/formatDate';
import { logger } from '../utils/logger';
jest.mock('../utils/logger'); #A
describe('formatDate', () => {
it('formats the date to YYYY-MM-DD', () => { #B
const result = formatDate(new Date('2025-07-25'));
expect(result).toBe('2025-07-25');
});
it('logs the formatted date', () => { #C
formatDate(new Date('2025-07-25'));
expect(logger.log).toHaveBeenCalledWith('Formatted date: 2025-07-25');
});
});
The unit test mocks an external logger and checks that a message was emitted. It illustrates testing a logging call, not a structured log format. section 5.4




















