#1 2014-09-06 09:06:02

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Daily Log File

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

#2 2014-09-06 09:19:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Daily Log File

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.

Offline

#3 2014-09-06 10:55:14

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Daily Log File

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

#4 2014-09-06 10:57:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Daily Log File

Yes, this is feasible, of course.
smile

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.

Offline

#5 2014-09-06 11:58:05

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Offline

#6 2014-09-09 13:49:33

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Daily Log File

For those who are wondering, this feature has been added in.

Thanks Arnaud!

Offline

#7 2014-09-09 15:36:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Daily Log File

Yes, and documentation updated.

Feedback is welcome!
Especially the "at fixed hour" feature - I just fixed one issue http://synopse.info/fossil/info/609a27477c
smile

Offline

#8 2014-09-21 08:20:59

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Daily Log File

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

#9 2015-04-14 14:36:54

cassianobs
Member
Registered: 2015-04-14
Posts: 1

Re: Daily Log File

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

Board footer

Powered by FluxBB