Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Managing Log Files.
Author | Message | ||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Started writing this to manage log files. (For/Next loop just for testing. Should be DO WHILE?). Basically finding the next sequence number & renaming the current file to the next in line.... IE, [Code] files \ <DIR> GARMIN 45 FOX.TXT 13783 TEMPLOG.TXT 13 TEST.TXT 1368691 TESTLOG.TXT 33 TEST_001.LOG 33 TEST_002.LOG 33 TEST_003.LOG 1 directory, 7 files > [/code] Doesn't work as the NAME function is not implemented in MMbasic. Does anyone have any alternate suggestions? Thanks Phil |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
Using the DIR$() function you could search through the list of files rather than opening and closing them. You could then just create the log file with the correct name in the first place. You could also hang on for V5.4 (due in a few weeks). That has long file names so you could name the files with the full date and time. With a bit of luck it might even have a NAME command. Geoff Geoff Graham - http://geoffg.net |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9082 |
I do my log files on a monthly basis, so as to not end up with too many log files. I do mine like this: SUB WRITE_SYSLOG(T1$) Local TXT$,MREF$,FILE$ CHDIR "\SYSLOG\" Do While FILE_OPEN_FLAG:Loop 'Wait till file handle closed if still open. FILE_OPEN_FLAG=1 'File handle is now closed, so set flag again for this sub MREF$=MTH$(val(mid$(date$,4,2)))+"_"+MID$(DATE$,7) 'Build a reference for current month FILE$=MREF$+".LOG" Open FILE$ for append as #4 TXT$="["+date$+", "+time$+"] - "+T1$ Print #4,TXT$ If DEBUG Then Print FILE$+" - "+TXT$ Close #4 FILE_OPEN_FLAG=0 'Indicate to system that file handle is closed. END SUB To log, I just issue the command: WRITE_SYSLOG ("Log this text."), for example. If the file already exists, the data will be date-stamped and added to the end of the file. If the file does not exist, it will be automatically created. [Quote=Geoff]You could also hang on for V5.4 (due in a few weeks). That has long file names[/Quote] Owwwwwww! Exciting. What kind of long-filename support are we talking about here? Smoke makes things work. When the smoke gets out, it stops! |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Current thoughs were a Static Logfile name that is archived periodically, maybe based on size, to the sequential names. From the manual, [Quote]The function will return the first entry found. To retrieve subsequent entries use the function with no arguments. ie, DIR$( ). The return of an empty string indicates that there are no more entries to retrieve.[/quote] From the example given I see output of [code]> print dir$("*.*",file) TEST.TXT > print dir$() TESTLOG.TXT > print dir$() FOX.TXT > print dir$() TEST_001.LOG > print dir$() TEST_002.LOG > print dir$() TEST_003.LOG > print dir$() TEMPLOG.TXT > print dir$() > [/code] Does that imply that there is no sort applied, with files listed in the order of their directory entry creation? Phil |
||||
Print this page |