How do I make a timer do this...

Posted by Weston on Wed 26 May 2004 12:38 AM — 14 posts, 50,367 views.

#0
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4192

The URL shown above is where this started.
My question is:

How do I make a timer that would check the filesize of the current log file every hour and then close and re-open that log file if it is 500 kilobytes or larger.

By 'close and re-open' I mean close/end the current log file, and open/begin a new log file for the data past that 500 kilobytes limit.
Australia Forum Administrator #1
You reminded me just in time. :)

I have added a new selector to world.GetInfo which returns the size of the current log file.

Thus, you want a timer that (say every hour) does this:


if GetInfo (231) > 500000 then
  CloseLog
  OpenLog "", 0
end if


You need version 3.50 onwards to do this.

The OpenLog with an empty filename will take the file name defined in the logging configuration window, which will need to have the date/time in it to avoid overwriting the same file each time.

#2
That sounds pretty cool, but how do I get version 3.50?
The website only mentioned version 3.45.

Is there a way to get a similar function with version 3.45?
USA #3
Version 3.50:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4248&page=999999

Nick only updates the main page once releases have a signifigant change, as well as have been bug tested. Mentality is if youre on the forums, you wont just give up when something goes wrong (because youre more than just a normal user). So rather than have a bunch of people with broken clients, its just us.
#4
That's pretty cool.
Thanks for explaining that to me, Flannel.

I'll go get 3.50 now and try out the new selector.
#5
I am noticing a problem...

I created a timer that repeats ever 30 minutes, in the "Send:" area I pasted (replacing 500000 with 2000000)


if GetInfo (231) > 2000000 then
CloseLog
OpenLog "", 0
end if


It works, but the new log file isn't being created. When the timer fires and the log file is over 2,000,000 bytes, that file is closed, but a new file isn't begin and so logging ends. I have to click the "Log Session" button on the toolbar to start the logging again.

Any guesses on what's wrong?
Australia Forum Administrator #6
Do you have a log file name in the logging configuration area? The OpenLog with no filename will not work unless you do.
#7
When you say, "file name in the logging configuration area" do you mean the 'Logging configuration area' that is under 'General'?

I do already have a file name in the 'Automatically log to this file:' field.


Did I did interpret your question correctly?
Australia Forum Administrator #8
Yes, you did. Oops, you found a bug in the OpenLog routine.

OpenLog with an empty file name will not work as documented.

As a work-around until the next version supply your own file name (eg. the log file with the date/time manually inserted into it).
Greece #9
It would be nice if you released bugfix releases if bugs were found, like 3.50 build whatever or something like that. It's annoying to have to live with a bug :( Unless you have the next version half-written and you have to release the bugfix, that would be a bit of a hassle... Are you using a CVS? You could just branch and fix the bug without losing the current version.
#10
Does the bug mean that OpenLog can not expand the date/time/hour variables used in the Logging configuration either?

I first tried to use:


if GetInfo (231) > 500000 then
CloseLog
OpenLog "MUD log %b %d %Y (%H %M).htm", 0
end if


That didn't work. It seems like when I hit 2MB, the logging stopped, and no new file was started. Then I tried to use:


if GetInfo (231) > 500000 then
CloseLog
OpenLog "C:\Program Files\MUSHclient\logs\MUD log %b %d %Y (%H %M).htm
end if


That gave me a file which was named "MUD log %b %d %Y (%H %M).htm".



Supplying a filename like OpenLog "MUD log (2)" might be good, but won't the filename that I specify be overwritten each time? Since I am unable to use the %b %d %Y (etc.) variables that I usually use.
Australia Forum Administrator #11
Yes, I am saying that OpenLog will not expand variables. If it did I would have suggested what you have tried. For now, use some VBscript date functions to manually insert the relevant parts of the date.

For example, the VBscript DatePart function (which breaks dates up into the component parts) combined with Now, should do it.

For example, this gives the day:

/world.note DatePart ("d", Now)

To save you looking it up, here are the other letters you can use:

yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second

#12
I feel really stupid asking this since it seems like I'm suppose to know what do at this point, uhm, but I don't.

How do I modify the existing:


if GetInfo (231) > 2000000 then
CloseLog
OpenLog "", 0
end if


...to use the VBscript DatePart?
Australia Forum Administrator #13
It depends how you want your file name formatted, but something like this.

Replace: OpenLog "", 0 by:


OpenLog "MyLogFile " _
        & DatePart ("h", Now) & ":" _
        & DatePart ("n", Now) & " " _
        & DatePart ("d", Now) & "-" _
        & DatePart ("m", Now) & "-" _
        & DatePart ("yyyy", Now) & " " _
        & " log.txt", 0


This will open a log file like:

MyLogFile 14:22 28-6-2004 log.txt

The DatePart sections are pulling various numbers out of the date (hour, minute, day, month, year) and adding them into the file name.