Quick revision
The short answer
Every payment line appears twice because of appender additivity: an event logged to com.shop.payment is written by that logger's own appenders and then passed up to the root logger's appenders, and both reference the same CONSOLE appender. We fix it either by setting additivity="false" on the com.shop.payment logger so events stop there, or by not attaching the console appender to the child logger at all and only setting its level, letting root do the writing. The same duplication often appears in Spring Boot when logback-spring.xml includes Boot's base configuration and then adds its own console appender.
What to remember
In this answer, we saw that additivity sends every event to the logger's own appenders and then to its ancestors' appenders, so a child logger and root that both reference CONSOLE write each payment line twice. We fixed it either with additivity="false" on com.shop.payment, accepting that it then misses root's future appenders, or more simply by setting only the level on the child logger and letting root write. We also saw the Spring Boot version of the problem, where base.xml already attaches a console appender to root, and how to send payment logs to their own file without the console.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Every payment line appears twice because of appender additivity: an event logged to com.shop.payment is written by that logger's own appenders and then passed up to the root logger's appenders, and both reference the same CONSOLE appender. We fix it either by setting additivity="false" on the com.shop.payment logger so events stop there, or by not attaching the console appender to the child logger at all and only setting its level, letting root do the writing. The same duplication often appears in Spring Boot when logback-spring.xml includes Boot's base configuration and then adds its own console appender.
Why this question is asked
Duplicate log lines look harmless, but they double log volume and cost, confuse anyone counting errors, and make alerts fire twice. The cause is always the same mechanism, which is why interviewers like the question: if we understand how an event travels through the logger hierarchy, the fix is obvious, and if we do not, we tend to delete random lines from the configuration until it stops. In this answer, we will recap how events travel up the hierarchy, reproduce the duplicate, apply both fixes, check the Spring Boot variant of the same problem, and finally send payment logs to a separate file without the console.
1A Quick Recap of Additivity
In Logback, loggers form a tree by their names: com.shop.payment is a child of com.shop, which is a child of root. When code logs through com.shop.payment.PaymentService, the event first goes to the appenders attached to that logger, if any, and then to the appenders of its parent, its grandparent and so on up to root. This is called additivity, and it is on by default for every logger.
Additivity is usually what we want. It is why a single console appender on root is enough to see logs from every package. The trouble starts when we attach an appender to a child logger as well, because then the event meets appenders at two levels of the tree.
2Reproducing the Duplicate Lines
Here is a configuration like the one in the question. The new logger for payments references CONSOLE, and root references CONSOLE too.
4 messages in order. Play them, or step through them one at a time.
The event is delivered once per logger that references CONSOLE on its way up.
Notice that order logs print once and payment logs print twice. The appender is the same object both times; it is simply called twice for the same event, once by each logger that references it.
3Fix 1: Stop the Event at the Payment Logger
If the payment logger needs its own appender, for example because we later point it at a different destination, we set additivity="false" on it. The event is then written by the payment logger's appenders and goes no further up the tree.
There is a catch: with additivity off, any appender added to root later, such as a JSON appender for the log platform, will not receive payment events. Additivity false means opting out of everything above, so we should use it deliberately and note why in the configuration.
4Fix 2: Set Only the Level on the Child Logger
Often the original goal was simply to see DEBUG output for payments. For that we do not need an appender on the child logger at all. We set the level and let the event travel up to root's console as usual.
This is usually the better fix, because it keeps one place, root, responsible for output, and any appender added to root later still receives payment events. Remember that root's INFO level does not drop the payment DEBUG events: the level is checked once, at the payment logger, whose own level is DEBUG.
5The Spring Boot Variant of the Same Problem
Spring Boot ships a default Logback configuration in base.xml, which defines CONSOLE and FILE appenders and attaches both to root (the file defaults to spring.log in the temporary directory; check your version). A logback-spring.xml that includes base.xml and then defines another console appender and attaches it to root, or to a child logger, produces the same duplicates.
The fix is to include only the parts we want: defaults.xml for the conversion rules and properties, and console-appender.xml if we want Boot's console appender, instead of base.xml. Then root has exactly the appenders we list. When chasing any duplicate, it helps to print the configuration at startup with <configuration debug="true"> or the Logback status listener, which shows each appender attached to each logger.
6Follow-up questions
How would you send payment logs to a separate file but not to the console?
Define a file appender, for example a RollingFileAppender writing payment.log, attach it to the com.shop.payment logger, and set additivity="false" on that logger so its events do not continue to root's console. If payment errors should still reach the console, add a second appender-ref on the payment logger to a console appender with a ThresholdFilter at ERROR, rather than turning additivity back on.
Could the duplicate come from two appenders writing to the same console?
Yes, and the effect looks identical. If root itself references two console appenders, such as Boot's CONSOLE and our own, every event is written twice even with no child loggers involved. Logback's status output at startup lists the appenders per logger, which tells the two causes apart quickly.
Does Log4j2 behave the same way?
Yes. Log4j2 LoggerConfig elements have the same additivity attribute, true by default, and an event goes to the appenders of the matching LoggerConfig and then to those of its parents. The fixes are the same: additivity="false" on the logger, or no AppenderRef on the child.
7Conclusion
In this answer, we saw that additivity sends every event to the logger's own appenders and then to its ancestors' appenders, so a child logger and root that both reference CONSOLE write each payment line twice. We fixed it either with additivity="false" on com.shop.payment, accepting that it then misses root's future appenders, or more simply by setting only the level on the child logger and letting root write. We also saw the Spring Boot version of the problem, where base.xml already attaches a console appender to root, and how to send payment logs to their own file without the console.
Open with
This is appender additivity. In Logback, when PaymentService logs, the event first goes to the appenders attached to the com.shop.payment logger, and then, because additivity is true by default, it continues up the hierarchy to the parents' appenders, ending at root.
Then, if they want more
Here both the payment logger and root reference the same CONSOLE appender, so the same event is written twice. Order logs print once because only root has an appender. There are two fixes. The first is to set additivity="false" on the com.shop.payment logger, so the event stops after the payment logger's own appenders.
That works, but it also means any appender we later add to root, like a JSON appender for the log platform, will not see payment events, so I would only do it when the payment logger really needs its own destination.
The second, which I usually prefer, is to remove the appender-ref from the child logger and only set its level to DEBUG, so the events travel up to root and are written once. Root's INFO level does not drop them, because the level is checked once at the logger that was called.
I would also check the Spring Boot variant: if logback-spring.xml includes base.xml, root already has Boot's console appender, and adding another console appender to root duplicates everything, so I would include defaults.xml and only the appender files I want. Turning on Logback's status output at startup shows which appenders are attached to which loggers.
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 "After adding an appender for the logger com.shop.payment in logback.xml, every payment...": https://scrivio-interview-library.netlify.app/java/java-logging/ebd47e3979/