Max Log Size

VC++ 6, ATL, STL, Non-MFC

My application writes logs and now I want to setup a max log size that is configurable by the user.   I'm trying to come up with the best way of doing that without having to load up the full log into memory, which could be 2MB, then starting from the end, delete data off the top.    Is there a better way or does someone have a function that already does this?
LVL 4
ChizlAsked:
Who is Participating?
 
AxterCommented:
Check out the logging library, in the following link:
http://axter.com/ezlogger/

The method I use, is to have two log files.  When the primary log file reaches the maximum length, I delete the old version, and rename the current log file.
Then create a new log file with the standard name.

if (maxsize)
{
  //Close file
  //Rename file to log.old
  //Create new file with standard name
}
0
 
ChizlAuthor Commented:
Thought of that, but unfortunatly, thats going to make it 2 logs with the max size, I only want 1.
0
 
Infinity08Commented:
>> Thought of that, but unfortunatly, thats going to make it 2 logs with the max size, I only want 1.

Then make 2 logs of half the max. log size ;)

The solution using two log files is a lot easier than removing from the file, and adding to it. Is there a specific reason that you only want one file ?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ChizlAuthor Commented:
Client specification
0
 
AxterCommented:
>>Client specification
Many times client specifications do not lead to what is best for the client, and it's up to the developer to clarify that with the client, so that they can make an inform decision on their specifications.

The two log method is the cleanest most efficient method I found to do this.
There are other methods, that would put an impact on performance, which i would not recommend.
0
 
Infinity08Commented:
Well, another easy "solution" is to just erase the log file once it reaches a certain size, and start over. Although you will have periods with no or little logs ... Is that a problem ?
0
 
ChizlAuthor Commented:
Erasing is a problem..   I'm going to go with the multiple logs..   2MB max, then 1MB archive, with a 1MB working log..    They wanted the 1 file and I figured there was an good way to do that, but guess not.  

Thanks for everyone's help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.