I have simple log setup in application.properties:
logging.file = logs/debug.log
logging.level.org.hibernate.SQL = DEBUG
logging.level.org.hibernate.type = TRACE
I have a package co.myapp.notifier
. I want all classes of this package to log to logs/notifier.log
. I tried
https://stackoverflow.com/a/9652239
and
https://stackoverflow.com/a/728351
with no luck.
In all cases the messages goes to my debug.log
Spring Boot's default configurations provides a support for the use of Java Util Logging, Log4j2, and Logback. Using these, we can configure the console logging as well as file logging. If you are using Spring Boot Starters, Logback will provide a good support for logging.
26.3 File Output By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging. file or logging. path property (for example, in your application.
If you need to do that, you will need your own logback.xml
file.
<configuration>
<!-- Normal debug log appender -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>debug.log</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<appender name="virtuallab" type="ch.qos.logback.core.rolling.RollingFileAppender">
<file value="Logs/virtuallab.log"/>
<appendToFile value="true"/>
<maxSizeRollBackups value="5"/>
<maximumFileSize value="5MB"/>
<rollingStyle value="Size"/>
<staticLogFileName value="true"/>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root level="debug">
<appender-ref ref="FILE" />
</root>
<!-- Specify the level specific to co.myapp.notifier -->
<logger name="co.myapp.notifier">
<level value="ALL" />
<appender-ref ref="virtuallab" />
</logger>
</configuration>
If you need a console log, you may need to add it as well. Here is the docs and read this question also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With