SoFunction
Updated on 2025-05-15

How to save to relative path using Logback log

illustrate

When using Logback, you need to save the output log, but there is a problem with the path when saving

Project background

  • Win7
  • Java Web + Tomcat 7.0 (in the D disk directory)
  • Logback 1.1.7

Case 1

File configuration

<!-- Path name -->
<property name="" value="logs" />
<!-- Saved file name -->
<property name="" value="log" />

Note: value=“logs”
If configured in this way, the log file will be saved to the directory where the project is started.
That is D:\tomcat7.0\bin\logs\

Case 2

File configuration

<!-- Path name -->
<property name="" value="/logs" />
<!-- Saved file name -->
<property name="" value="log" />

Note: value=“/logs”
If this is configured, the log file will be saved to the system directory.
That is, D:\logs\

Case Three

File configuration

<!-- Path name -->
<property name="" value="../logs" />
<!-- Saved file name -->
<property name="" value="log" />

Note: value=“../logs”
If this is configured, the log file will be saved to the system directory.
That is D:\tomcat7.0\logs\

Summarize

The relative saving path settings of files can be divided into the following three types:
1. value=“logs”– means to save it to the program running directory, in tomcat it is the bin directory
2. value=“/logs”– means to save to the system directory
3. value=“../logs”– Indicates the parent directory saved to the program running directory

This is the article about how to use Logback logs to save to relative paths. For more related Logback log saving content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!