ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Another more efficient way would be to use two (or even more) files: Begin by filling the first file until it reaches 1MB; then open the second file and keep on writing to this until it is full. Now blank the first file again and log to this for the next 1MB and so on... This way you can review at least your desired last 1MB and won't have to worry about performance, because you only append and truncate (both are cheap file operations), so there is no buffer and no additional string operation needed. But of course this has to fit into your software design
iam using this method only right now but i got review comments from my manager tat , after i fill up the 2 files,i create a new one and delete the old one, but the concept is jus the insertion of a single record will be followed by the loss of 1MB of data (though we have 1MB more at hand) still it sounds a bit odd to him, thats the reason i am trying other methods. and my system generates a lot of messages at a very short interval of time .
ya i thot of tat too ... logrotate removes old files after a regular time interval right (say once in a day )? so incase if there are no log files being generated in my system , then all my log files become older by time so they may be deleted but i may need them for debugging(1MB of log data is needed all the time) , so because of this reason i dint opt for it , but may be u cud correct me if am wrong, exactly how does logrorate operate ?
i will keep 5 files each of 200KB and i have a circular buffer for 200kb and my msgs goto tat buffer and from it i write each file after the buffer gets filled so it will b a 200kb write each time to the file rather than writing file for every msg. after filling up 5 files i delete the first and create a new one and rename the others and will carry on doing this continuously
so how does this concept sound ? any issues tat any of u cud find ?
Last edited by Deepak Inbasekaran; 04-12-2006 at 01:34 AM.
I wouldn't wait with the writing until the buffer is full. This may cause that you will loose the last 200kb during a crash. There is nothing wrong with writing some text to the end of a file. At least as long this won't happen several thousand times per second. The rest sounds good.
ya the problem is my system is generating 1000s of msgs at a short time so i prefer the buffer approach rather than writing each time to the file . also i plan to have some code tat writes off the data in the buffer to a file before the crash.