Logging system failed to initialize using configuration from ‘classpathlogbacklogback-spring.xml‘

2021-12-31:

The project can run normally on the Windows system, but when it is moved to the Mac system, an error occurs!!

According to the error message, the initialization of "logback-spring.xml" failed, and the configuration error of "Logback" was detected, and the illegal statement was abnormal.

Failed to create parent directory of '[/apps/logs/sns_error.log]'...

The main reason is that the initialization of the configuration file failed, and then some errors occurred.

First look at the log file input location defined in the configuration file, as shown in the figure below.

The specific error information is as follows:

Logging system failed to initialize using configuration from ‘classpath:logback/logback-spring.xml’
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ERROR] - Failed to create parent directories for [/apps/logs/sns_error.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ERROR] - openFile(/apps/logs/sns_error.log,true) call failed. java.io.FileNotFoundException: /apps/logs/sns_error.log (No such file or directory)
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[WARN] - Failed to create parent directories for [/apps/logs/sns_warn.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[WARN] - openFile(/apps/logs/sns_warn.log,true) call failed. java.io.FileNotFoundException: /apps/logs/sns_warn.log (No such file or directory)
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[INFO] - Failed to create parent directories for [/apps/logs/sns_info.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[INFO] - openFile(/apps/logs/sns_info.log,true) call failed. java.io.FileNotFoundException: /apps/logs/sns_info.log (No such file or directory)
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG] - Failed to create parent directories for [/apps/logs/sns_debug.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[DEBUG] - openFile(/apps/logs/sns_debug.log,true) call failed. java.io.FileNotFoundException: /apps/logs/sns_debug.log (No such file or directory)
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[TRACE] - Failed to create parent directories for [/apps/logs/sns_trace.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[TRACE] - openFile(/apps/logs/sns_trace.log,true) call failed. java.io.FileNotFoundException: /apps/logs/sns_trace.log (No such file or directory)

Let's continue with the above.

It should be because I don’t know much about its features when I just used Mac. I don’t know if this is caused by the different computer environment (this directory cannot be created on Mac)

I will first record the problems I encountered, and I will continue to add when I find a solution. I also hope that netizens who encounter such problems will give a solution for your reference.

Follow-up: 2021-12-31 PM

Background explanation: On the Windows system, my project is placed in a folder on the D: drive, and today I found the "/apps/logs" directory on the D: drive, just like the path in the configuration shown in the figure below.

When I changed the input location of the configuration file to "/apps/logs/sns", the "sns" folder appeared on the D: drive.

As shown below:

This shows that when the value in this configuration is "relative path", it will be created under the root directory of the disk where the project is located (for example: if the project is on the D: drive, the path is "D:+relative path").

Follow-up: 2021-12-31

Open the folder and found that the following log was created, and then look at the error message, which can fully explain the cause of the error: the folder path cannot be created, and then the log file cannot be created, and the log file fails to open.

Then reported an error! !

The created log file is shown in the following figure:

The error message is shown in the figure below:

The solution must start from why the file path is not created on the Mac.

There is no concept of disk partitions on Mac. Is it because of this reason that paths cannot be created.

Also as a rookie, I can only grope step by step to solve the problem, so that I can understand the problem more deeply. I also hope that some big guys can give pointers.

Finally found a solution! ! !

The dramatic thing is that when I remove the backslash at the beginning of "/apps/logs/sns" on the Mac and change it to "apps/logs/sns", it runs successfully! !

In this case it will write this path in the directory of the project.

Let me introduce myself first. The editor graduated from Jiaotong University in 2013. He used to work in a small company, went to big factories such as Huawei, OPPO, and joined Alibaba in 2018. Until now. I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore and grow by themselves or enroll in classes, but the tuition fee of nearly 10,000 yuan for training institutions is really stressful. My unsystematic self-study is very inefficient and long, and it is easy to hit the ceiling and the technology stops. Therefore, I collected a copy of "A Complete Set of Learning Materials for Java Development" and gave it to everyone. The original intention is also very simple, that is, I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden. Add the business card below to get a full set of learning materials

Guess you like

Origin blog.csdn.net/m0_67402341/article/details/126075153
Recommended