Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log File

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi

I want to create a log report in txt format just to trace the transactions occur during data entry, edit view and printing etc.
How can I do so?

Thanks

Saif
 
There are several ways to do this. The following is one suggestion:

Code:
SET ALTERNATE TO c:\logs\mylogfile.txt
SET ALTERNATE ON

* Do other stuff here

* Start the processing that you want to log
? "This is some text describing the action to be logged"
? "Here is some more logging text"

* More stuff here

SET ALTERNATE OFF
SET ALTERNATE TO

The point is that all the ? commands between SET ALTERNATE ON and SET ALTERNATE OFF will send text to the log file. Obviously, you can write whatever text you like.

I assume that you have also done SET CONSOLE OFF (to prevent the text also appearing on the screen).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for the reply,

In LAN environment how can I add the activity in the same file (mylogfile.txt) from different users.

Saif
 
There's no easy way to let several users update the same text file. It would be better to use a DBF to hold the log.

Instead of writing a line of text for each transaction, you would insert a record into the DBF. The record would be a single memo field, containing whatever text you want to use to record the transaction. (But you can also have other fields, for example for the datetime of the transaction and the user ID).

You could then use a report to view the log file. This would be an ordinary report, showing the fields in the DBF, perhaps filtered on date range or user ID. Or you could create a form with a grid, and use that to view the log. The point is that the log would be an ordinary table, so you can use whatever VFP features you like to update and report on it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I wonder if it wouldn't be simply possible to replace the local file name c:\logs\mylogfile.txt with a LAn filename, either mapped drive with the same drive letter for all users, or full UNC name with servername, eg \\yourserver\some share\logs\log.txt

If ALTERNATE would cause a file handle open, surely only one user would be able to write. A DBF is a godd suggestion, as you can also add a datetime field and more for later evaluation, etc.

But if a text file is enough, I'd suggest to simply use STRTOFILE("logtext"+chr(13)+chr(10),"\\yourserver\some share\logs\log.txt",.T.) to append to a file.

Bye, Olaf.
 
I vote for StrToFile() rather than SET ALTERNATE. I add a property and method to the application object of my applications to make this easy:

Property is cLogFile and is set to initialize to something like:

=FORCEPATH("MyLog.LOG", SYS(2023))

so it lands in the Temp folder.

Then, the method is AddToLogFile and looks like this:

Code:
LPARAMETERS cString

STRTOFILE(TTOC(DateTime()) + ": " + m.cString, This.cLogFile, .T.)

RETURN

With this mechanism, I can add logging anywhere in the application with just:

goApp.AddToLogFile("Something to log.")

Tamar
 
OK, Tamar and Olaf. Your STRTOFILE() has beaten my SET ALTERNATE into submission. But I would still play my DBF against your text file.

With a DBF, there's so much more you can do with the data: sort it, filter it, query it, browse it, report on it. I would also guess that inserting record would be faster than STRTOFILE() with the third parameter set to .T.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for the explanations of different options, actually I want event viewer type of thing.

Saif
 
I have to say: The event log is local for each user, so you don't have a central log this way. As your goal is "to trace the transactions occur during data entry" using your own log meachnism to DBF or TXT is the better solution.

As craig says in his paper: "The Windows Event Log should not be used as a tracing tool or to record transactional information such as database changes."

Actually, if you want a transaction log of database changes, use stored procedures triggers and eg TaxRI is capable to do audit trail of data changes.

Bye, Olaf.
 
DBF vs. TXT depends on the scope and purpose of the log, I think. For the application where I really worked out my logging logic, I'm dealing with a VFP EXE and 4 VFP COM objects, all writing to a single log. The application can run for days at a time, so I have code that swaps out the log file when it gets to a certain size. In this case, I think text is better.

That said, I can see cases where a DBF might be a better choice.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top