Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 22:07 18 May 2024 Privacy Policy
Jump to

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: Australia
Posts: 1664
Posted: 12:54am 17 May 2017
Copy link to clipboard 
Print this post

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]

  Quote   for n=1 to 10

Filename$=
"Test_"+Str$(N,3,0,"0")+".log"
Open FileName$ for Input as #1
Print Filename$; " MM.Errno = "; MM.ERRNo
If MM.ERRNo=0 Then Close #1

If MM.ERRNo=6 Then
Name
"Test.log" as FileName$
Exit for
End If

Next n



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: Australia
Posts: 3167
Posted: 01:38am 17 May 2017
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9082
Posted: 02:34am 17 May 2017
Copy link to clipboard 
Print this post

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: Australia
Posts: 1664
Posted: 02:35am 17 May 2017
Copy link to clipboard 
Print this post

  Geoffg said   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.


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


To reply to this topic, you need to log in.

© JAQ Software 2024