java Spring Boot records logs in files according to date limit size

In the above java Spring Boot writes logs to files, we implement another effect of writing console logs to local files of the project.
But there is a problem here
. For example, my project is a large-scale enterprise project with one million users every day. If the access is recorded in the same file every day, isn’t it the same as not remembering it?
How to find things? Moreover, in the Windows system, if the size of the notepad is larger than 4G, it cannot be opened directly. It does not require 40G. Even if it is more than ten G, it will freeze.

We can write like this to open the configuration file in the yml format I use here.
We add the code.

logging:
  file:
   name: serve.log
  logback:
    rollingpolicy:
      max-file-size: 10MB
      file-name-pattern: server.%d{
    
    yyyy-MM-dd}.%i.log

Insert image description here
The meaning of these two sentences is to set the maximum 10MB for each file. If it exceeds, change a file to record it.
Then the following tells it that the name format of our log file is server. The percent sign d here means that we set the time format to Year YYYY-month MM-day dd. Which file.log

But 10MB is a bit too large for testing. Let’s just change it to 10KB.
Let him change the next file quickly. Normally, setting 10MB is more appropriate.
Insert image description here
Then we start the project.
Obviously there is not enough information and no file is produced.
Insert image description here
I will adjust a few more here. The secondary interface allows him to produce more logs.
Insert image description here
Then when we go back and look, we can see that when the content is very large, it will automatically change
Insert image description here
the file format. The file format is also the current year, month and day plus the number of files.

Speaking directly, there is no such a good console on the server. If you can see the error, you have to rely on the log to troubleshoot the problem. Therefore, the log reflection must be complete. Can you locate the customer's problem as soon as possible?

Guess you like

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