Video in progress
When do you use each log level (TRACE, DEBUG, INFO, WARN, ERROR)?
ERROR means the work wasn't done and somebody should look; WARN means something odd happened but the system carried on; INFO is for important business events; DEBUG and TRACE are detailed information for developers, usually off in prod.
📖 Answer
A simple rule: in prod, who reads this log line and what do they do?
ERROR: a request failed, a payment didn't go through, a message was lost. Logs at this level are often wired to alerts, so don't write ordinary cases like "the user typed the wrong password" as ERROR.WARN: it succeeded after a retry, the cache didn't work and we fell back to the DB, a deprecated parameter arrived.INFO: the service started, an order was created, a scheduler finished its run.DEBUG: what went into a method, which condition fired.TRACE: very fine detail: every iteration, the raw payload.
log.info("Buyurtma yaratildi: orderId={}, userId={}", order.getId(), userId);
log.warn("Kesh javob bermadi, bazadan o'qiymiz: key={}", key);
log.error("To'lovni yuborib bo'lmadi: orderId={}", orderId, ex);
The most common mistake in practice is writing everything as ERROR or everything as INFO. The real error then gets lost in the noise.
Sign up to mark studied questions and save your progress.