Debug Log size restrictions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srikanth21
    New Member
    • Dec 2012
    • 1

    #1

    Debug Log size restrictions

    Hi,

    Iam creating one debug log in my c++ application through the below code.
    Code:
    file *log;
    log = fopen("C:\\snmp\\Applicationlog.txt", "w");
    iam writing the statements in to this log by using fprintf().
    As the .exe where i have put this mechanism runs continuously,th e size of log file is increasing gradually.

    Could you please let me know
    1)If there is any way to restrict the Log file size,if the file reaches the mentioned size,the file should be discarded and logging should be done in another file with the same name.
    {OR}
    2)Put a time interval,once after that interval is elapsed, a new log file should be created.
    Last edited by zmbd; Dec 26 '12, 03:45 PM. Reason: [Z{fixed code tag}]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You might consider a circular file.

    This is a file you create and you make all the records in the file the same length. The first record has some control information.

    OK. Say you create 1000 records of 100 bytes each. That would be 999 records for the log and 1 record for control informaton. At this point the control information is 1 indicating that the next record to write is 1.

    Write your log entry in record 1. The control information is set to 2 so the next log entry goes in record 2.

    When the control information becomes 1000 (the size of the file) it is reset to 1.

    This control information is actually the "end of the log".

    To read the file, you seek to the end of the log and then start reading records in reverse order. When you get to 0 you seek to record 999 and cntinue until you get to the "end of the log".

    These types of logs run forever and never need maintenance. You just create them to hold enough informtion for your purposes.

    Obviously, you implement this by writing a series of functions to create, delete, write and read the file.

    One thing I have done is to reserve 1 byte at the beginning of a record to be 1 (the record contains data) or 0 (the record is empty. This allows me to "empty the log" if I need to.

    Comment

    Working...