java Spring Boot writes logs to files

For our previous set of operations, the logs were all on the console.
But if your project is running in the formal environment and the operation and maintenance personnel suddenly tell you that the log error is reported, but your logs are only on the console, what if the company's project If the number of visits is very large, it will be difficult for you to find a certain log on the console.

At this time we can use a file to write it down.
We open the project and find the configuration file. Here I use application.yml.
We only need to add the code in it.

logging:
  file:
   name: serve.log

Insert image description here
That's fine.
Then we start the project directly.
Insert image description here
Here you can see our log file. When
Insert image description here
we open it, we can see the content.
Insert image description here
Here I adjust the interface to let him take the log.
Insert image description here
Here our console log is output.
Insert image description here
We
Insert image description here
can look at the log file again. After seeing our content, we went up.
In fact, it is really not necessary to set the log format, because many people say that if you open it directly in local++ or notepad, there is no color difference at all,
so there is really no setting when setting up the log. Anyway, the color is used as a notepad for others to see, mainly so that problems can be found through the logs.

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/133466465