How to setup a log file in Spring Boot

This is a very short guide to get a log file setup for a Spring Boot Application.

Spring uses Logback as its default logging system, and automatically logs to the console.

To setup a log file in the resources folder of your app (where lives ), create a file called logback.xml  (copy / paste below).

This will create a log file called my-app-logfile.log in the logs dir of your app.

<?xml version="1.0" encoding="UTF-8"?>
    <property name="LOGS" value="./logs" />
    <appender name="Console"
        <layout class="ch.qos.logback.classic.PatternLayout">
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
    <appender name="RollingFile"
            <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
            <!-- rollover daily and when the file reaches 10 MegaBytes -->
    <!-- log everything at info level -->
    <root level="info">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />
 	<!--  you can log only the things you want at whatever level like this (ie your packages etc, and then set the one above to error
 			or something as your not interested in it
    <logger name="" level="info" additivity="false">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />


Leave a Comment