Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain what TRACE, DEBUG, INFO, WARN and ERROR should mean in a backend service, and classify these events: a request validation failure from a client, a retry that succeeded, a database connection lost and then restored, a payment provider returning 500 after all retries.

ERROR means the service failed to do something it should have done and someone may need to act; WARN means something unexpected happened but was handled, or the service is degraded; INFO records important business and lifecycle events; DEBUG and TRACE are diagnostic detail for developers. So a client validation failure is DEBUG or INFO, a retry that succeeded is DEBUG (WARN only if it becomes frequent), a lost connection is WARN with an INFO when it is restored, and a payment provider failing after all retries is ERROR with the order and correlation ids.

Why this question is asked

Log levels look like a beginner topic, but they decide what wakes people up at night, what the log bill looks like and whether the important line can be found during an incident. Teams that never agree on their meaning end up with ERROR logs nobody reads and real failures hidden among them. Interviewers ask this question with concrete events because classifying them shows whether we think about who reads a log line and what they should do with it. In this answer, we will define each level by the reader and the action it implies, then classify the four events one by one, explaining the reasoning, and finish with the question of logging and rethrowing.

1A Quick Recap: Levels Are About the Reader

A log level is a label on each event that tells the logging framework, and later the people searching logs, how important the event is. Loggers have a threshold: a logger set to INFO writes INFO, WARN and ERROR and drops DEBUG and TRACE. In production, application code usually runs at INFO.

The most useful way to define levels is by asking who will read the line and what they should do. That turns a vague scale of importance into a rule we can apply in code review.

What each level should mean
LevelMeaningReader and action
ERRORthe service failed to do its job for a request or taskon-call; may need to act
WARNunexpected but handled, or running degradedon-call or owner; watch the trend
INFObusiness and lifecycle eventsanyone reconstructing what happened
DEBUGdiagnostic detail of decisions and valuesdeveloper, switched on when needed
TRACEvery fine detail, every step or payloaddeveloper, rarely and briefly

2A Request Validation Failure From a Client

A client sends an order with a negative quantity, and we return 400 Bad Request. Is that an error? For the client, yes. For our service, no: the service did exactly what it should do, which is to reject bad input. Nobody on our team needs to act, so ERROR is wrong, and WARN is too strong as well, because a 400 is expected behaviour.

I would log it at DEBUG, or at INFO if the team wants a record of rejected requests, with the field that failed and a request id, but never the whole payload. The rate of validation failures is a metric, not a log question: if 400s jump from 0.1 percent to 15 percent after a client release, a dashboard on the metric shows it immediately, while thousands of log lines would not.

Java
// Wrong: the client made the mistake, but our on-call sees an ERROR
log.error("Validation failed", ex);
// Better: low level, no stack trace, identifiers only
log.debug("Rejected order request {}: {} {}", requestId, ex.getField(), ex.getReason());
// DEBUG Rejected order request r-77f: quantity must be greater than 0

3A Retry That Succeeded

A call to the inventory service timed out once and succeeded on the second attempt. The request was served correctly, so from the user's point of view nothing went wrong. Logging every successful retry at WARN would produce a steady stream of warnings in any distributed system, because occasional timeouts are normal.

So the individual retry belongs at DEBUG, with a retry counter metric next to it. If retries become frequent, that is worth a WARN, but once per incident rather than per attempt: for example, a WARN when the retry rate in the last minute crosses a threshold, or when a circuit breaker opens. One WARN that says 'inventory calls are being retried at 12 percent' is far more useful than 4,000 lines saying 'retrying'.

4A Database Connection Lost and Then Restored

Here the service is genuinely degraded for a while: requests may be failing or waiting. That is the definition of WARN. The key detail is to log the change of state, not every attempt. The connection pool may try to reconnect every 500 milliseconds; writing a WARN for each failed attempt turns a two-minute outage into 240 identical lines.

Java
// Log transitions, not attempts
if (wasHealthy && !healthy) log.warn("Database connection lost: {}", cause.getMessage());
if (!wasHealthy && healthy) log.info("Database connection restored after {} s", outage.toSeconds());
// WARN Database connection lost: Connection refused
// INFO Database connection restored after 94 s

The INFO on restore closes the story: someone reading the logs later sees exactly when the degradation started and how long it lasted. If the connection stays down so long that requests fail, those failures are reported at the place that handles them, which brings us to the last event.

5A Payment Provider Returning 500 After All Retries

The provider failed, we retried three times, and we still could not take the payment. The service failed to do its job for this order, and the customer is affected. This is ERROR. The line should carry the information someone needs to act: the order id, the correlation or trace id, the provider's response code, the number of attempts, and the exception with its stack trace.

Java
log.error("Payment failed for order {} after {} attempts, provider status {}",
orderId, attempts, status, ex);
// ERROR Payment failed for order 1042 after 3 attempts, provider status 500 [traceId=4bf92f35]
// java.io.IOException: 500 Internal Server Error ...

But notice that the alert should not be one page per ERROR line. If the provider is down, we will get hundreds of these in a minute. The alert should be based on the rate of payment failures from a metric, for example more than 2 percent of payments failing over five minutes, and the log lines give the detail once someone is looking.

6Follow-up questions

Should you log and rethrow an exception?

Usually not. If a repository logs the exception and rethrows it, then the service logs it and rethrows it, and the controller advice logs it again, the same stack trace appears three times at ERROR, and the error count triples. The rule is to log an exception once, at the place that handles it, which is the place that decides what happens next, such as returning a 500 or sending a message to a dead letter topic. Lower layers should either handle it or rethrow it with added context in a wrapping exception, not both.

Where do DEBUG and TRACE differ in practice?

DEBUG is for decisions and key values a developer needs to follow the flow, such as which pricing rule was chosen. TRACE is for very detailed output, such as every row read or full request and response bodies. TRACE is rarely enabled even in development, and it is the level most likely to contain sensitive data.

Is a 404 Not Found an error?

Usually not for the service. A client asking for an order id that does not exist is normal, so DEBUG or INFO with the id is enough. It becomes interesting only when the rate changes, which, again, a metric shows better than a log level.

7Conclusion

In this answer, we defined levels by their reader and the action they imply: ERROR when the service failed and someone may need to act, WARN when something unexpected was handled or the service is degraded, INFO for business and lifecycle events, DEBUG and TRACE for diagnostics. We classified a client validation failure as DEBUG or INFO, a successful retry as DEBUG with one WARN if retries become frequent, a lost and restored connection as one WARN and one INFO, and a payment failure after all retries as ERROR with identifiers, alerting on the rate rather than on each line.

What to say in the interviewAbout 90 seconds aloud

Open with

I think of levels in terms of who reads the line and what they should do. ERROR means the service failed to do something it should have done, so someone may need to act.

Then, if they want more

WARN is unexpected but handled, or a degraded state. INFO is important business or lifecycle events, like an order placed or the application started. DEBUG and TRACE are diagnostic detail that we switch on when needed.

For the examples: a request validation failure is the client's mistake, and the service did its job by returning 400, so it's DEBUG or maybe INFO, with identifiers but not the payload, and the rate belongs in a metric.

A retry that succeeded is DEBUG; if retries become frequent I'd want one WARN per incident, for example when a retry rate threshold is crossed or a circuit breaker opens, not one per attempt.

A database connection lost and then restored is a WARN when it's lost and an INFO when it's restored, logging the state changes rather than every reconnect attempt.

And the payment provider returning 500 after all retries is a real ERROR: the customer's payment failed, so I log it once with the order id, the trace id, the status and the exception.

I would still alert on the rate of payment failures from a metric, not on each ERROR line, because during a provider outage there will be hundreds of them.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain what TRACE, DEBUG, INFO, WARN and ERROR should mean in a backend service, and...": https://scrivio-interview-library.netlify.app/java/java-logging/89063788f1/