Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- std::ofstream logfile(config::logname, std::ios::app);
- std::streambuf *const old_buffer = std::clog.rdbuf(logfile.rdbuf());
- // .. the guts of the application
- std::clog.rdbuf(old_buffer);
- }
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- void logworker()
- {
- ino_t inode = 0;
- FILE *logfile;
- logfile = fopen(logfilename, "a+");
- while(running)
- {
- struct stat mystat;
- if (stat(logfilename, &mystat)!=0 || mystat.st_ino != inode)
- {
- logfile = freopen(logfilename, "a+", logfile);
- inode = mystat.st_ino;
- }
- while (stuff_in_buffer)
- {
- fwrite(); /* etc */
- }
- fflush(logfile);
- /* sleep until something interesting happens */
- }
- }
Add Comment
Please, Sign In to add comment