Solved

Log File Implementation.

Posted on 2004-08-04
6
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
An API detour question 7 105
Arduino EDI - Programming language 3 122
Why is compiler in oracle server ? 9 109
Windows Server 2008 R2: %HOMEDRIVE%%HOMEPATH% Incorrect 4 85
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 opening and writing to files 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.

739 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