Scrivio Interview library
CodingFoundations7 min read · updated 12 November 2026

Configure a Spring Boot service to write logs to /var/log/app/app.log, roll at 50 MB, keep 14 days and at most 2 GB in total, and change the console pattern to include the thread name.

With Spring Boot's default Logback setup, we only need properties: logging.file.name=/var/log/app/app.log, logging.logback.rollingpolicy.max-file-size=50MB, max-history=14 and total-size-cap=2GB, optionally a file-name-pattern for the archives, and logging.pattern.console with %thread in it. These properties only apply while Boot configures Logback for us; with our own logback-spring.xml we configure the appenders ourselves. And in containers we would usually skip the file entirely and write to stdout for the platform to collect.

Why this question is asked

Logging to a file is still common on virtual machines and older servers, and a log file without limits is one of the classic ways a service fills a disk and stops at 3 a.m. Interviewers ask this coding question to see whether we know Spring Boot's logging properties well enough to avoid writing XML, and whether we understand what each limit means. In this answer, we will recap how Boot configures Logback, write the properties for the file and rolling policy, change the console pattern, see when the properties stop working, and finish with the container case.

1A Quick Recap of How Boot Configures Logging

Spring Boot uses Logback by default, through spring-boot-starter-logging. If we do not provide our own logback.xml or logback-spring.xml, Boot sets Logback up itself, with a console appender and, if we ask for one, a file appender. Many parts of that default setup can be changed with logging.* properties in application.properties or application.yml, so for a common requirement like ours we do not need any XML.

By default Boot writes only to the console. It writes to a file when we set logging.file.name, a full path to the file, or logging.file.path, a directory in which Boot creates a file called spring.log. If both are set, logging.file.name wins. A rolling policy, which means renaming the active file and starting a new one when it reaches a size or a new day begins, is already part of Boot's default file appender; we only adjust its limits.

2Writing the Properties

Here is the whole requirement as properties.

Properties
# application.properties
logging.file.name=/var/log/app/app.log
logging.logback.rollingpolicy.max-file-size=50MB
logging.logback.rollingpolicy.max-history=14
logging.logback.rollingpolicy.total-size-cap=2GB
logging.logback.rollingpolicy.file-name-pattern=/var/log/app/app-%d{yyyy-MM-dd}.%i.log.gz
logging.pattern.console=%d{ISO8601} %-5level [%thread] %logger{36} - %msg%n
# console: 2026-11-05 10:42:01,317 INFO [http-nio-8080-exec-3] c.a.orders.OrderService - order 42 saved
Step throughWhen Logback rolls and deletes
  1. Write the event to app.log
  2. app.log over 50 MB or a new day?
    YesRoll: rename to app-2026-11-05.0.log.gzNoKeep writing
  3. Any archive older than 14 days?
    YesDelete itNoKeep it
  4. Archives over 2 GB in total?
    YesDelete the oldest until under the capNoDone

4 steps in order. Play them, or step through them one at a time.

Let us read it line by line. logging.file.name points Boot at the active file. The directory must exist and be writable by the user the service runs as; Logback creates the file, but a missing permission only shows up as an error at start-up.

max-file-size=50MB rolls the active file when it reaches 50 MB. The file-name-pattern decides the archive names: %d{yyyy-MM-dd} adds the date, so a new day also starts a new file, %i is the index for several files on the same day, and the .gz ending tells Logback to compress archives, which typically shrinks text logs by about ten times. Boot's default pattern is ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz, so we only set it if we want different names.

max-history=14 keeps archives for 14 periods of the date pattern, which with a daily pattern means 14 days. total-size-cap=2GB is a second, independent limit: if the archives together exceed 2 GB, Logback deletes the oldest ones even if they are younger than 14 days. Notice that we need both limits. During a noisy incident, a service can write 5 GB in one day, and max-history alone would happily keep 14 such days.

3Changing the Console Pattern

The console pattern is a Logback pattern string. %d{ISO8601} prints the timestamp, %-5level prints the level padded to five characters so columns line up, [%thread] prints the thread name, %logger{36} prints the logger name shortened to about 36 characters (com.acme.orders.OrderService becomes c.a.orders.OrderService), %msg is the message and %n a line break.

The thread name is the requested addition, and it is a useful one: http-nio-8080-exec-3 tells us the line came from a request, scheduling-1 from a scheduled job, and task-2 from an @Async method. Notice that setting logging.pattern.console replaces Boot's whole default pattern, including its colours and, in recent versions, its correlation id section, so we add back anything we want to keep, such as %X{traceId}. There is a matching logging.pattern.file for the file; if we want the thread name in the file too, we set that as well.

4When the Properties Stop Working

These properties only configure Boot's own default Logback setup. If the project has a logback-spring.xml that defines its own appenders, Boot no longer builds the file appender for us, and the logging.logback.rollingpolicy.* properties have no effect unless the XML refers to them. This is the most common reason someone says "I set max-history but old files are never deleted".

XML
<!-- logback-spring.xml: reuse Boot's defaults so the properties still apply -->
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="LOG_FILE" value="${LOG_FILE:-/var/log/app/app.log}"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</configuration>

If we need custom XML, including Boot's defaults.xml and file-appender.xml like this keeps the property-based limits working. Otherwise we write our own RollingFileAppender with a SizeAndTimeBasedRollingPolicy and set maxFileSize, maxHistory and totalSizeCap in the XML. The same applies to Log4j2: its configuration file controls rolling, and the Logback properties do nothing there.

5In Containers, Prefer stdout

On Kubernetes or another container platform, writing to /var/log/app inside the container is usually the wrong design. The container's file system is lost when the container is replaced, a full log file can fill the node's disk, and the platform already captures stdout and stderr and lets a node agent ship them. So in containers we leave logging.file.name unset, keep only the console appender, ideally with structured JSON through logging.structured.format.console, and let the platform handle rotation and shipping.

The file configuration we wrote is the right answer for a VM or a bare-metal server, where an agent tails /var/log/app/app.log. A neat way to support both is to set the file properties only in a profile or through environment variables on the VMs, so the same jar logs to stdout in containers and to a capped file elsewhere.

6Follow-up questions

What is the difference between logging.file.name and logging.file.path?

logging.file.name sets the exact file, such as /var/log/app/app.log. logging.file.path sets only a directory, and Boot writes spring.log inside it. If both are set, logging.file.name is used. Most teams prefer the name, so the file is called after the service rather than spring.log.

Does max-history count days or files?

It counts periods of the date pattern in the archive name. With the usual daily pattern %d{yyyy-MM-dd}, it means 14 days, regardless of how many size-based files each day produced. That is why total-size-cap is needed as a separate limit on the space used.

Can we clean old archives when the application starts?

Yes. logging.logback.rollingpolicy.clean-history-on-start=true makes Logback apply the history and size limits at start-up, which helps after a period when the service was down and no rolling happened. Without it, old archives are only removed when the next roll occurs.

7Conclusion

In this answer, we configured Spring Boot's default Logback setup with properties only: logging.file.name for the file, max-file-size=50MB, max-history=14 and total-size-cap=2GB for rolling and cleanup, an optional file-name-pattern with compression, and logging.pattern.console with %thread. We saw that both limits are needed, that the properties stop applying once a custom logback-spring.xml defines its own appenders unless it includes Boot's defaults, and that in containers we would rather write to stdout and let the platform collect logs.

What to say in the interviewAbout 80 seconds aloud

Open with

With Boot's default Logback setup I can do all of it with properties. I set logging.file.name to /var/log/app/app.log, which turns on Boot's rolling file appender for that path.

Then, if they want more

Then logging.logback.rollingpolicy.max-file-size is 50MB, so the file rolls at 50 megabytes, max-history is 14, which with the default daily date pattern keeps fourteen days of archives, and total-size-cap is 2GB, which deletes the oldest archives once all of them together pass two gigabytes.

I need both limits, because on a noisy day the service could write several gigabytes and history alone would keep it. Optionally I set file-name-pattern, for example with the date, an index and a .gz ending so archives are compressed.

For the console I set logging.pattern.console to something like ISO8601 date, level padded to five, the thread name in brackets, the logger shortened to 36 characters, the message and a newline. That replaces Boot's whole default pattern, so I would add back the trace id if we use one.

I would also point out that these properties only work for Boot's own default configuration: with a custom logback-spring.xml they do nothing unless it includes Boot's file-appender.xml. And in containers I would not write a file at all; I would log JSON to stdout and let the platform collect it.

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 documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
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 "Configure a Spring Boot service to write logs to /var/log/app/app.log, roll at 50 MB...": https://scrivio-interview-library.netlify.app/spring-boot/boot-logging/8a9a38af82/