Question

I have a service that controls an RS-232 device and logs actions to a file. I am to write another service which will read the log file line by line and run some queries on a database then delete all the logs.

My concern is about read and write conflicts on the file. For example, the logger service open the file to append a new line at the same time the replicator service opens the file and write "" so truncate its content.

Any suggestions to clarify my situation?

Was it helpful?

Solution

How about modifying the "read" service to rename the file first (putting a "_" in front of it is what I usually do). And then it can delete it when done. The write service should create the log file if it does not exist. This way you should have zero data loss.

OTHER TIPS

If your are not tied to use a file, the use case would suggest a message queue for handing over your log messages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top