Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Logging Messages to a Background Log File

Keywords:    logging messages

Question:

I am a new WinBatch user and I would like to know how I can Log messages and errors in a ASCII-text-file.

Answer:

There is no "automatic logging" but you can do stuff like....
;This is my main code
Message("Hello",1)

logmsg="Hello we are at point 1"
gosub loglog

Message("GoodBye",2)

logmsg="Hello we are at point 2"
gosub loglog

exit


;the logging subroutine
fn="c:\temp\loglog.txt"
fh=FileOpen(fn,"APPEND")
FileWrite(fh,loglog)
FileCLose(fh)
return
However, there's a lot of overhead in repeatedly opening and closing a file like that. So here's another example to set up a TRC file to trace its execution. The trace file is opened and closed only once. It's created in the same directory as the WBT file.

The only problem with this method is that the trace can't be viewed until the program finishes running. If you do want to look at some variables *while* it's running, you can either Display(), Message() them, or write them to an INI-type file with the IniWritePvt() function, because INI-type files can be viewed while they're being written to.

nm = "BASIC"
fc = StrSub(nm,1,1)
trc = "C:\WBT\%fc%\%nm%.TRC"
ft = FileOpen(trc,"WRITE")
FileWrite(ft,StrCat(DateTime(),"%nm%: begin"))

FileWrite(ft,"This is a comment")
a=2
FileWrite(ft,"a = %a%")

;-------
:Done
;-------
FileWrite(ft,"")
FileWrite(ft,StrCat(DateTime(),"%nm%: end"))
FileClose(ft)
Exit
The output looks like this:
Wed 97-04-23 18:29:23 BASIC: begin

This is a comment
a = 2

Wed 97-04-23 18:29:24 BASIC: end 

Article ID:   W13284
Filename:   Logging Messages to a Log File.txt