Click here to Skip to main content
15,920,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need log the data to a file (filename.log). After the file size reaches 1 MB, the data should be moved to another file (say filename_1.log) and the new data should be logged to "filename.log". This should happen in a circular format. Maximum number of files 5.

Need Help.

Thanks in advance
Posted
Updated 20-Mar-14 1:56am
v2

1 solution

hi,
this link has some good code .. see the dr.dobbs links for better understanding[^]
a good approach would be to create a separate class for logging say CLogger and use it through out the project. Make clogger.h and put in it all the relevant function's declarations for example the renaming of existing file 'curentlog.log' to 'oldlog1.log' when it crosses 1 mb, and the date and time functions etc. Then implement these functions in the respective .cpp file.
start by creating a single log file and see if you are able to get info written to it. Then proceed ahead.
Remember 'Google' is your best friend for everything you need .
This is also a good way to see how singleton pattern works[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900