This works well but slows down the whole program considerably. If the logs are huge, the program execution is delayed.
If I run this code from RAM disk(RAM disk I/O is much faster than disk I/O), things are good. but if logs are huge, having all the logs on RAM will not make much sense given that RAM disk has limited space.
For the code that we have written in go, we have used logrus for logging which works well.
Can someone please suggest a faster way to redirect the logs from console to a file. I can’t change anything in the C library.
You say that the C library “by default” dumps logs to the console. I understand that you cannot modify the C library, but is there any way to configure it to dump to a file directly?
I’m curious if the slowdown is because of Go or if it’s perhaps because dumping to disk is just slow. If you don’t do anything in your code to handle the redirection from stdout or stderr to disk and then redirect from your console, does it still slow down or is it fine?
Stop asking for writes to be really, really, really slow. Don’t O_SYNC.
$ man open
O_SYNC
Write operations on the file will complete according to the re‐
quirements of synchronized I/O file integrity completion (by
contrast with the synchronized I/O data integrity completion
provided by O_DSYNC.)
By the time write(2) (or similar) returns, the output data and
associated file metadata have been transferred to the underlying
hardware (i.e., as though each write(2) was followed by a call
to fsync(2)).