Solved

Log File Implementation.

Posted on 2004-08-04
6
232 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
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 and use structures 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.

895 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

13 Experts available now in Live!

Get 1:1 Help Now