Page 1 of 1

Writing job log event entries repeatedly to the file

Posted: Thu Nov 28, 2013 5:18 am
by DSRajesh
Hi All

I am using below code for writing log entries into the file but the log entries are writing repeatedly.

Code: Select all

PENSEQ InFile to output_file    
                 
ElSE CREATE output_file                               
ELSE ERRORCODE=1

For x = 1 to LCnt  
                           
LId = LogIdList<x>                                    

vEventDetail = vEventDetail:Field(DSGetLogEntry(hJob,LId),"\",4) 
WRITESEQF vEventDetail to output_file                             
ELSE STOP
WEOFSEQ output_file
Next 

CLOSESEQ output_file
is there any issue with code which is writing to file.

Re: Writing job log event entries repeatedly to the file

Posted: Thu Nov 28, 2013 5:35 am
by ArndW
The following should clear up your problem

Code: Select all

OPENSEQ InFile to output_file
THEN
   WEOFSEQ output_file   
END
ELSE 
   CREATE output_file ELSE ERRORCODE=1
END

For x = 1 to LCnt  
   LId = LogIdList<x>                                    
   vEventDetail = vEventDetail:Field(DSGetLogEntry(hJob,LId),"\",4) 
   WRITESEQ vEventDetail ON output_file ELSE STOP "Bad Write"
   ** WEOFSEQ output_file !! Don't do this, it writes an end-of-file marker and truncates the file
NEXT X
CLOSESEQ output_file

Posted: Thu Nov 28, 2013 6:41 am
by DSRajesh
premium membership got expired and unable to see the content.

Request you please post the same as visble and i will renew the membership in a week

Posted: Thu Nov 28, 2013 7:16 am
by ArndW
The WEOFSEQ command truncates the sequential file each time it is executed, you have that statement inside your loop. Otherwise I just cleaned up the code a little.

Posted: Thu Nov 28, 2013 7:43 am
by DSRajesh
Thanks Arndw,

I am able to cleanup the file and write without repeated log entries in the file.

But the entries are writing one after another on the same line rather than writing on new line for each new entry.

what needs to be added to write the each log entry in next line ..

Please suggest me on this

Posted: Thu Nov 28, 2013 7:56 am
by ArndW
Writing to a sequential file using WRITESEQ will terminate each line. Could it be that your server is on UNIX and you are viewing in Windows? (UNIX uses <LF> while Windows uses <CR><LF>). If that is the case, try using wordpad.exe or notepad++.exe to read the sequential file. If you need windows-type termination when writing in UNIX, add the "Char(13)" to each string line you write with WRITESEQ.

Posted: Thu Nov 28, 2013 9:08 am
by DSRajesh
Arndw,

The server is on unix.
I am able to see the characters  before and after each entry.

Posted: Thu Nov 28, 2013 9:16 am
by ArndW
Make a test copy of the routine that writes only 2 (preferably short) lines to a file, then use the UNIX "od" command to dump that to see what you are getting as control characters. I would expect to see only char(10) (<LF>) after the data.

Posted: Thu Nov 28, 2013 9:43 am
by DSRajesh
Arndw,

Whenever logentry has (...) end the end which has expandable content in the log,i am getting these characters and the line termination is proper

Posted: Thu Nov 28, 2013 10:35 am
by ArndW
I can't check right now, but assume that your log entries contain either a field-mark or value-mark. If you mask those with spaces, i.e. with "vEventDetail = vEventDetail:CONVERT(@FM:@VM,' ',Field(DSGetLogEntry(hJob,LId),"\",4))" what does your output look like?

Posted: Thu Nov 28, 2013 11:36 am
by DSRajesh
Thanks Arndw,

This is working fine and those control charcaters were removed and entries are showing correctly.

Posted: Thu Nov 28, 2013 11:59 am
by chulett
We had this same 'control character' conversation back in your "Extract of log file using DSGetLogEntry not working" thread. :wink:

Posted: Thu Nov 28, 2013 2:16 pm
by DSRajesh
That was for diff conversion

Posted: Thu Nov 28, 2013 3:05 pm
by chulett
Same principle, though.