Quick revision
The short answer
ConsoleAppender writes to standard output or standard error, FileAppender to a single file and RollingFileAppender to a file that it rotates by size or by time. An async appender, Logback's AsyncAppender or Log4j2's Async appender and async loggers, hands events to a background thread so the calling thread does not wait for slow output, while syslog, socket, Kafka and JDBC appenders ship logs over the network from inside the application, which adds new ways for it to fail. For a Spring Boot service in Kubernetes, the usual choice is the console appender with structured JSON output, collected from stdout by a node agent such as Fluent Bit, Vector or the OpenTelemetry Collector, because files inside containers need volumes and rotation and disappear with the pod.
What to remember
In this answer, we went through the common appenders. Console, file and rolling file appenders write locally, async appenders move the write to a background thread through a bounded queue whose overflow behaviour we must choose, and syslog, socket, Kafka and JDBC appenders ship logs over the network from inside the application, bringing remote failures into our process. For a Spring Boot service in Kubernetes, we chose JSON on the console, collected by a node agent that adds metadata, buffers and retries, and avoided files inside containers.
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.
ConsoleAppender writes to standard output or standard error, FileAppender to a single file and RollingFileAppender to a file that it rotates by size or by time. An async appender, Logback's AsyncAppender or Log4j2's Async appender and async loggers, hands events to a background thread so the calling thread does not wait for slow output, while syslog, socket, Kafka and JDBC appenders ship logs over the network from inside the application, which adds new ways for it to fail. For a Spring Boot service in Kubernetes, the usual choice is the console appender with structured JSON output, collected from stdout by a node agent such as Fluent Bit, Vector or the OpenTelemetry Collector, because files inside containers need volumes and rotation and disappear with the pod.
Why this question is asked
Choosing where logs go sounds like a configuration detail, but it decides how the application behaves when things go wrong: whether a full disk stops the service, whether a broken network slows down requests, and whether the logs survive the restart we needed them for. Interviewers ask this question to see whether we know the options and can match them to the runtime. In this answer, we will recap what an appender is, go through the local appenders, then the async wrappers, then the network appenders and their risks, and finally choose an appender setup for Kubernetes.
1A Quick Recap of Appenders
An appender is the component of a logging framework that takes a logging event and delivers it to a destination. Each appender has an encoder or layout, which turns the event into text or bytes, and may have filters, which decide which events it accepts. Appenders are attached to loggers, usually to the root logger, and an event can be delivered to several appenders at once. Both Logback and Log4j2 come with a set of standard appenders, and their names map closely onto each other.
| Appender | Writes to | Typical use |
|---|---|---|
| Console | stdout or stderr | containers, local development |
| File | one file | rarely alone; it grows without limit |
RollingFile | a file rotated by size or time | virtual machines, bare metal |
| Async (wrapper) | another appender, from a background thread | decoupling slow I/O from requests |
| Syslog / Socket | a remote server over UDP or TCP | legacy log collectors |
| Kafka / JDBC | a broker topic or a database table | rarely wise inside the application |
2Local Appenders: Console, File and Rolling File
ConsoleAppender writes each event to standard output, or standard error if configured. It is the simplest appender and, in containers, the most useful, because the container runtime captures standard output and keeps it in files on the node, where collectors can read it.
FileAppender writes to one file and never stops growing, so on its own it is rarely right for a long-running service. RollingFileAppender adds a rolling policy: when the file reaches a size, or a new day or hour begins, it closes the current file, renames or compresses it and starts a new one, and it deletes archives beyond a retention limit. That is the standard choice on virtual machines.
3Async Appenders: Decoupling the Caller From I/O
Normally an appender writes on the thread that called log.info(), so if the disk or the console is slow, that request thread waits. An async appender changes this. Logback's AsyncAppender wraps another appender: the calling thread only puts the event into a bounded queue, and a background thread takes events from the queue and passes them to the wrapped appender. Log4j2 has an equivalent Async appender, and also fully async loggers built on a lock-free ring buffer, which are faster still.
The catch is the queue. When it fills up because output is slower than input, something must give: either the caller blocks until there is room, or events are dropped. Logback's AsyncAppender, by default, starts discarding TRACE, DEBUG and INFO events when the queue is 80 percent full and blocks when it is completely full, unless neverBlock is set to true. We should choose this behaviour deliberately and know that some events may be lost if the process dies with a full queue.
4Network Appenders and Their Risks
Syslog, socket, Kafka and JDBC appenders send events directly from the application to a remote system. They are tempting because they skip a separate shipping agent, but they bring the remote system's failures into our process. When the remote side is slow or down, the appender either blocks the calling threads, buffers in memory until the heap fills, or drops events. Each appender has its own reconnect behaviour, timeouts and buffer sizes, and the defaults are not always safe.
There is also a recursion risk. A Kafka appender uses a Kafka client, which logs too; if those logs are routed back into the same appender, they can loop or deadlock, so the client's own loggers must be sent elsewhere. For these reasons, most teams keep network delivery out of the application and let an external agent do it.
5What to Use in Kubernetes
In Kubernetes the standard pattern is simple. The application writes structured JSON to standard output with the console appender, one event per line. The container runtime stores stdout in files on the node, rotates them, and a node agent running as a DaemonSet, such as Fluent Bit, Vector or the OpenTelemetry Collector, reads those files, adds Kubernetes metadata such as pod name, namespace and labels, buffers to disk and retries when the back end is unavailable. The application never knows where its logs end up.
- Spring Boot service
ConsoleAppenderwith JSON encoder - Container runtimecaptures stdout to node files, rotates them
- Node agent (DaemonSet)Fluent Bit, Vector or OpenTelemetry Collector; buffers and retries
- Log back endsearch, retention, alerting
4 layers, from the top down. Step through them one at a time.
JSON matters because multi-line stack traces in plain text get split into separate records by line-based collectors; in JSON, the stack trace is one escaped field of one record. Before Spring Boot 3.4, the same result came from an encoder such as logstash-logback-encoder.
Writing to files inside a container is the option to avoid. The container's file system disappears when the pod is deleted or rescheduled, which is exactly when we need the logs. Keeping files requires a volume, a rolling policy inside the application and an agent that reads the volume, which is more moving parts than stdout with no benefit.
6Follow-up questions
Why is a database appender a risky choice for a busy service?
Every log event becomes an insert into a database, so a service logging 2,000 events per second adds 2,000 writes per second, competing with the business workload for connections and I/O, possibly on the same database. When the database slows down, logging slows down the requests, or the appender's buffer fills and events are lost. Log tables also grow fast and need their own cleanup. A log store built for the job, fed by an agent, avoids all of this.
Should we wrap the console appender in an async appender in Kubernetes?
Often it is not necessary, because writing to stdout is usually fast. If profiling shows request threads waiting in the console appender, for example because the node is slow to drain container logs, an async wrapper with neverBlock set to true helps, at the price of possibly dropping events under pressure.
When would you still use a rolling file appender?
On virtual machines or bare metal, where there is no container runtime capturing stdout. Then the application writes to a rolling file with size and time limits and a total size cap, and a local agent reads the files and ships them.
7Conclusion
In this answer, we went through the common appenders. Console, file and rolling file appenders write locally, async appenders move the write to a background thread through a bounded queue whose overflow behaviour we must choose, and syslog, socket, Kafka and JDBC appenders ship logs over the network from inside the application, bringing remote failures into our process. For a Spring Boot service in Kubernetes, we chose JSON on the console, collected by a node agent that adds metadata, buffers and retries, and avoided files inside containers.
Open with
The basic appenders are the console appender, which writes to stdout or stderr, the file appender, which writes to one file, and the rolling file appender, which rotates the file by size or time and deletes old archives, which is what you want on a VM.
Then, if they want more
Then there are async appenders: Logback's AsyncAppender, or Log4j2's Async appender and async loggers, which put events in a bounded queue so a background thread does the slow I/O and the request thread does not wait. The important decision there is what happens when the queue is full, block or drop.
Finally there are network appenders, syslog, socket, Kafka or JDBC, which ship logs directly from the application. I avoid those in busy services, because when the remote side is slow or down, the application either blocks, fills its memory or loses events, and a JDBC appender puts a write on the database for every log line.
For a Spring Boot service in Kubernetes, I would use the console appender with structured JSON, one event per line, for example with Boot's structured logging property in 3.4 and later or a logstash encoder before that.
The container runtime captures stdout, and a node agent like Fluent Bit, Vector or the OpenTelemetry Collector adds pod metadata, buffers to disk and retries. JSON keeps stack traces in one record. I would not write files inside containers, because they need volumes and rotation and they disappear with the pod, which is exactly when you need them.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.4
- 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 "Name the common appenders in Logback or Log4j2 and say what each is used for: console...": https://scrivio-interview-library.netlify.app/java/java-logging/f8b95b750b/