Solved

Log File Implementation.

Posted on 2004-08-04
6
231 Views
Last Modified: 2012-05-05
Hi,
      I have to create a file and write into it.

Now in my program I start writing into the file.Now when I go more than 1 MB I will have to delete the first 20% of the file and shift the remaining to the top and start appending to the File...this should continue for ever until my program runs.

can sombody suggest me a simple and effective way of doing this..
0
Comment
Question by:deardeepan
6 Comments
 
LVL 4

Expert Comment

by:alikoank
ID: 11712994
> I will have to delete the first 20% of the file and shift the remaining to the top and start >appending to the File

The easiest way will be:

. when the file reaches treshold size open a new file
. copy the last %80 of original file into new file
. delete original file
. rename new file to original file.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11713127
look into log file rotation ... It will keep log file size in check and offer you far more flexibility
http://iain.cx/src/logrotate/

The approach you are using is not suitable for most applications .... Logrotate or some similar utility will fare better
What alikoank suggested is the way to go if you want to remove a part of the file
0
 

Author Comment

by:deardeepan
ID: 11713280
I am using Windows platform..

Is there any other way to do this..I will not be able to do log rotate wither.

is there somethinglike memap in UNIX ....equivalent in windows
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 11713296
ok since your file size is small, you can do this

read entire file in 1Mb buffer

memmove last three quarters to the beginning of the buffer ...

write the buffer back to the file
0
 
LVL 22

Accepted Solution

by:
grg99 earned 125 total points
ID: 11714582
>ok since your file size is small, you can do this

>read entire file in 1Mb buffer

>memmove last three quarters to the beginning of the buffer ...

>write the buffer back to the file

Er, how about just skip the memmove and:
    int twenty = sizeof(buffer) / 5;
    write( theFile,  buffer[  twenty  ], twenty * 4 );
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11715112
good idea grg99
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now