Do I need to be aware that browsing and copying log files during production are being written?

Asked 2 years ago, Updated 2 years ago, 308 views

log4j2 File Log Output If you want to browse and copy log files in the java app, click
Is it correct to stop, browse, and copy the app?

I wonder if it was not possible to refer to /var/log/syslog etc. such as a linux server while it was running...
I wonder if it's okay because the file lock is applied while writing the file and the reference copy is done after writing...

Until now, I have not opened the log file of the running application and the file has not been corrupted
Please tell me how it works.

linux windows

2022-09-30 21:53

1 Answers

If you don't add multiple processes to a single file, you won't have to worry about "file corruption".

tail-f file

It's common practice to show the contents of the file that's being added right now.

If you look at the process that you are writing while it is running, you may see a file that has stopped output at half the time.This is for buffering, not locking.The file writer may use a fixed-size buffer and output the file to the operating system using a timer that fills it up.In such a case, the program keeps logging, but the file prints out a lot, for example, every "4KB" accumulation.

In spite of this, the log output program sometimes goes to the operating system to write every line of output.

When it comes to "copying log files," it's better to stop the program (at least when the log output stops) before copying.You may be able to copy a file with a half-finished endings
If you don't want to stop the program, or if you can stand the fact that it's half-finished, it's okay.

In order to "guarantee" reading in clean units, the write side and the read side lock each, I can't think of a way to use the lock, but the log file won't do that much.

I think you can forget about the article on the link.I can give you an example of how to solve the problem, but it goes beyond the needs of this question.


2022-09-30 21:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.