Closed Mynock17 closed 9 years ago
Hi. Well its a complicated issue with many solutions...
Writing to a disk as you may know is blocking on Linux at least. Epoll or any others option does not work for disk files. In a C program the usual way would be to copy data to a buffer which another thread would write to disk, so the main thread could continue running. Unfortunately we do not have real OS threads in Lua.
The quick solution for logging at least would be to use piping from stdout and strerr to a file, another way would be to log using turboredis sub/pub? You can reimplement the turbo.log.functions any way you like in your application and the application itself will run using your functions. You could write a C extension which runs a thread that writes to logs or something. Personally I would probably just write to log files straight from Turbo or pipe data to files. If you are writing big files, you can write in chunks (say in 1MB size) and simply do a coroutine.yield() for every chunk, to make sure that other coroutines gets some execution time...
For distributed systems that runs over multiple nodes I would use Redis or some others system to gather logs from all nodes.
The quick solution for logging at least would be to use piping from stdout and strerr to a file
http://stackoverflow.com/questions/6674327/redirect-all-output-to-file
Thanks, @kernelsauce
Hi,
what is the right (turbo-) way to write non blocking to a file (i.e. for logging)?
Regards Bernd