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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to time date stamp each line of data in log file

Status
Not open for further replies.

Cuervo99

Technical User
May 20, 2003
2
US
I use Procomm Plus as a data logger to a text file. I want to time and date stamp each record that is received. Each record is ended with a CR LF.

I know it's got to be simple but I don't have a clue!
 
This depends on how are you logging the data to the text file. Are you currently using a script?
 
No, I,m not using a script at this time. The device outputs a data string every 5 to 30 seconds asynchronously.
 
I thing the following code should work (untested). Let me know if you have any problems with it.
Code:
string LogFile = "log.txt"        ;Name of Log File

proc main
when target 0 "^M" call LogEntry  ;Whenever a C/R is received,
                                  ;call the LogEntry procedure
while 1                           ;loop forever
   yield                          ;
endwhile                          ;
endproc

proc LogEntry
   string TimeString              ;String to store time
   string DateString              ;String to store date
   string LogString               ;String to store input
   
   ltimestrs $LTIME DateString TimeString ;Get time & date

   locate $ROW-1 0                ;Move cursor up 1 row
   termreads LogString 80         ;Read line to LogString
   locate $ROW+1 0                ;Move cursor back
   
   fopen 0 LogFile append text    ;Append Log File
      fstrfmt 0 "%s %s: %s`r`n" DateString TimeString LogString
   fclose 0
endproc
 
mrnoisy,

That's a great script. Is there anyway it would be able to log everything that comes up when you hit enter. Could it be modified to log sort commands on large lists?
 
What I really meant to say was:

Is there anyway it can be modified? I run sort statements that output multiple rows of data. The locate portion errors out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top