0
0
NextJSframework~20 mins

Error logging strategies in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Logging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding centralized error logging

Which of the following best describes the main benefit of using centralized error logging in a Next.js application?

AIt stores error logs only on the user's browser for privacy reasons.
BIt automatically fixes errors in the code without developer intervention.
CIt prevents errors from occurring by validating user input on the client side only.
DIt collects all error logs in one place, making it easier to monitor and analyze issues across multiple servers or environments.
Attempts:
2 left
💡 Hint

Think about how error logs from different parts of your app can be managed efficiently.

💻 Command Output
intermediate
2:00remaining
Next.js error logging output with Sentry

What will be the output in the Sentry dashboard after running this Next.js server-side code snippet that throws an error?

NextJS
import * as Sentry from '@sentry/nextjs';

export async function getServerSideProps() {
  try {
    throw new Error('Database connection failed');
  } catch (error) {
    Sentry.captureException(error);
    return { props: { error: error.message } };
  }
}
AThe error message is logged to the browser console only, not to Sentry.
BNo error is logged because captureException is asynchronous and not awaited.
CAn error event with message 'Database connection failed' appears in Sentry with stack trace.
DThe function returns a syntax error due to missing await keyword.
Attempts:
2 left
💡 Hint

Consider how Sentry captures exceptions even if not awaited.

Configuration
advanced
2:00remaining
Configuring log levels in Next.js with Winston

Given the following Winston logger configuration in a Next.js API route, which log messages will be saved to the file 'error.log'?

NextJS
import winston from 'winston';

const logger = winston.createLogger({
  level: 'warn',
  transports: [
    new winston.transports.File({ filename: 'error.log' })
  ]
});

logger.error('Critical failure');
logger.warn('Warning message');
logger.info('Informational message');
A'Critical failure' and 'Warning message' will be saved; 'Informational message' will be ignored.
BOnly 'Critical failure' will be saved; others ignored.
CAll three messages will be saved to 'error.log'.
DNo messages will be saved because the level is set incorrectly.
Attempts:
2 left
💡 Hint

Remember that log levels filter messages at or above the set level.

Troubleshoot
advanced
2:00remaining
Diagnosing missing error logs in production

A Next.js app uses a custom error logging middleware that writes errors to a remote logging service. In production, no error logs appear in the service. Which is the most likely cause?

AThe remote logging service is down, but the app logs errors locally instead.
BThe middleware is only applied in development mode and not included in the production build.
CThe app is catching errors but not throwing any exceptions.
DThe logging middleware is configured to log only warnings, but errors are not warnings.
Attempts:
2 left
💡 Hint

Check if the middleware is active in all environments.

🔀 Workflow
expert
3:00remaining
Implementing a robust error logging workflow in Next.js

Which sequence of steps correctly describes a robust error logging workflow for a Next.js app that uses Sentry and Winston?

A1, 2, 3, 4
B1, 3, 2, 4
C2, 1, 3, 4
D3, 1, 2, 4
Attempts:
2 left
💡 Hint

Think about capturing errors first, then reporting and logging, finally responding to the user.