You are not logged in.
Pages: 1
Hi Arnaud,
What is the best way to create a daily log file using TSynLog?
I am thinking of creating a descendant of TSynLog with the following changes:
1. Filename will include current date, perhaps in yyyymmdd format.
2. If the filename exists when creating log for the first time, append to it, otherwise create a new file.
3. Start a background thread that checks for date change, and when that happens, recreate a new fWriterStream.
Or is there already some built-in mechanism?
The reason I am looking for a daily log file is to make it easier to search for logs based on dates. So if the user wants to look for logs on a particular date, he just needs to open the file that corresponds to the date he wants using a log viewer.
Offline
Are you sure simple log file rotation is not enough?
It is easy to find out which file to open, according to the file timestamp.
In the current implementation, rotation is triggered by file size.
But it may be possible to change our code and trigger the file rotation by date.
Online
Rotation works too, if there is an event like OnArchive so that we can decide if we want to handle it (move it to a different folder, archive it with zip instead of SynLZ, etc). Would that be possible?
Offline
Yes, this is feasible, of course.
Just add a feature request, with the two points (i.e. trigger by date and callback to rotate file).
And a link to this forum thread, please, so that we could discuss later on.
Online
Offline
For those who are wondering, this feature has been added in.
Thanks Arnaud!
Offline
Yes, and documentation updated.
Feedback is welcome!
Especially the "at fixed hour" feature - I just fixed one issue http://synopse.info/fossil/info/609a27477c
Online
Hi Arnaud,
Would it make more sense to move the call to DeleteFile(fFileName) into the IF block before it?
The reason being that if the OnRotate event was handled (True was returned), it most likely means the programmer is saying "OK I have everything under control".
Also, would appreciate it if you could take a look at http://synopse.info/forum/viewtopic.php?id=2022
Thank you!
Offline
Sorry reopen this old and solved topic.
But I want to do this, a log every day.
My case is as follows, I have an application that runs every 5 min called by the Scheduler and the application writes to the log information on the routine that is performed. But a log every 5 min is impossible to search for a specific log, and I could not make the serious SynLog a log per day, making marge if the file already exists.
There is this feature?
Sorry for my English ..
Offline
Pages: 1