Solved

Log File Implementation.

Posted on 2004-08-04
6
235 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C#, VS15, StructLayout 1 135
SCANF - LIMIT THE NUMBER OF CHARARACTERS 1 66
Passing a array as parameter - C 2 100
Please explain C language error codes ? 5 27
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

861 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