Page 1 of 1

how to capture job log into text file

Posted: Mon Nov 20, 2006 6:03 am
by bikan
Hi All,

I want to capture job log information into text file. i have given this query in job control (c:\Ascential\DataStage\Engine\bin\dsjob -logdetail DMCProj1 CopyOfCon_Cons 1 20 > E:\DMC_Data\DSProjects\DMC_DEV\log\Con_Cons.txt). In this case log will dsplay based on event id but i want total log or only warnings.


Please give me solution.

Posted: Mon Nov 20, 2006 7:43 am
by ray.wurlod
Try -logsum option. If you want detail of all events then you're going to have to create a script (BAT file, perhaps) to loop through each event and append to file. Use -lognewest option to find the earliest event.

Print to file

Posted: Tue Dec 05, 2006 11:45 pm
by dssiddu
From The Director Client tool ,There print option from this u can directly print to file(.txt)

Posted: Wed Dec 06, 2006 1:12 am
by aakashahuja
The solution has to be a combination of using logsum and logdetail.

logsum with the option WARNING will give you al the warnings along with the event id's which could later be used with logdetail to detail each of them if required.

Posted: Wed Dec 06, 2006 3:37 am
by Zabeerulla
Hi,

Please find the Before/After Subroutine Code below. This routine will direct the log of the log into a text file. Call this routine in the Job Properties window and specify the type of the file (1 for text file ) and the directory in the Input Value field. It writes the log of that job under the specified directory.

* Routine Name : GetJobLog
*After Job subroutine which writes a Job log to a file
*InputArg is a string which can have 3 ';' seperated fields.
*Field 1 specifies the report type(0, 1 or 2) as recognized by DSMakeJobReport.
*Field 2 specifies the directory in which the report file will be written.
* Field 3 can be used to specify the XSL stylesheet to be refernced in the generated

$INCLUDE DSINCLUDE JOBCONTROL.H

ErrorCode = 0

ReportType = Field(InputArg,';',1)
DirName = Field(InputArg,';',2)
Stylesheet = Field(InputArg,';',3)
if ReportType = 2 then
Suffix = ".xml"
end
else
Suffix = ".txt"
end

JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)
JobInvId = DSJobInvocationId
if JobInvId ne "" then
JobName:= ".":JobInvId
end

JobStarted = convert(" :-","_",DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP))
Alias = ""
if JobInvId eq "" then
Alias = DSGetIdForJob(JobName,ErrorCode)
end
if Alias ne "" then
FileName = JobName:"_":Alias
end
else
FileName = JobName:"_":JobStarted
end

FileName := Suffix

If ReportType = 2 and Stylesheet ne "" Then
ReportType := ";":Stylesheet
End

StartTimeStamp = DSGetJobInfo (JobHandle, DSJ.JOBSTARTTIMESTAMP)
EndTimeStamp = DSGetJobInfo (JobHandle, DSJ.JOBLASTTIMESTAMP)

GetLogSum = DSGetLogSummary(JobHandle,DSJ.LOGANY,StartTimeStamp,EndTimeStamp,0)


Openpath DirName to t.fvar then
write GetLogSum to t.fvar, FileName else
call DSLogWarn("Failed to write file ":FileName:" to directory ":DirName, "DoJobReport")
end
end
else
call DSLogWarn("Failed to open directory ":DirName, "DoJobReport")
end

close t.fvar




Hope it helps.

Posted: Wed Dec 06, 2006 5:15 am
by ray.wurlod
That code is bad from a number of perspectives. I do hope you're not claiming authorship. What do you do with ReportType? Where do you call DSMakeJobReport? Why didn't you format the code and enclose it in Code tags?

Posted: Wed Dec 06, 2006 5:44 am
by Zabeerulla
Hi,

Sorry, forgot to customize the code as per the requirement. Call the routine from the Job Properties window and just specify the Directory Name where to create the log file in the Input Value field. Execute the job, it will create log of the job in the text file.

Please find the updated code below.

* Routine Name : GetJobLog
* Usage : Give the directory as the Input Value

$INCLUDE DSINCLUDE JOBCONTROL.H

ErrorCode = 0

DirName = InputArg

Suffix = ".txt"

JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)

JobStarted = convert(" :-","_",DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP))

FileName = JobName:"_":JobStarted


FileName := Suffix

StartTimeStamp = DSGetJobInfo (JobHandle, DSJ.JOBSTARTTIMESTAMP)
EndTimeStamp = DSGetJobInfo (JobHandle, DSJ.JOBLASTTIMESTAMP)

GetLogSum = DSGetLogSummary(JobHandle,DSJ.LOGANY,StartTimeStamp,EndTimeStamp,0)


Openpath DirName to t.fvar then
write GetLogSum to t.fvar, FileName else
call DSLogWarn("Failed to write file ":FileName:" to directory ":DirName, "GetJobLog")
end
end
else
call DSLogWarn("Failed to open directory ":DirName, "GetJobLog")
end

close t.fvar

Posted: Wed Dec 06, 2006 8:28 am
by chulett
I haven't checked everything, just wanted to make a couple of comments since we're exposing code to the world. I tend not to use multiple steps when a single step would do just as well, hopefully without 'over-loading' the statement into obfuscation. :lol:

For example, this:

Code: Select all

FileName = JobName:"_":JobStarted 
FileName := Suffix 
Could be replaced with this, is a little easier to read over the extra cool concatenation operator.

Code: Select all

FileName = JobName:"_":JobStarted:Suffix
I for one wouldn't equate DSJ.ME to another variable called JobHandle, I would use it directly. Right now, if you miss that assignment step when browsing the code, you get the mistaken impression it could work on any job when it fact it can only work on the job that calls it.

Code: Select all

JobHandle = DSJ.ME 
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME) 
JobStarted = convert(" :-","_",DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP)) 
This makes your intent clearer, in my opinion:

Code: Select all

JobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME) 
JobStarted = convert(" :-","_",DSGetJobInfo(DSJ.ME,DSJ.JOBSTARTTIMESTAMP)) 
You should also investigate the SEEK command which would allow you to append your output to the file rather than simply replace whatever was there. Off the top of my head SEEK file.variable, 0, 2 will advance your pointer to EOF. Double-check the BASIC Guide or search the forum for more examples.

Posted: Wed Dec 06, 2006 7:00 pm
by ray.wurlod
SEEK is not available unless the file was opened with OPENSEQ.

You have chosen to write the file into the directory as if it were a record in a database table, which is a perfectly valid approach. But it means you can not take Craig's suggestion to use SEEK.

Posted: Wed Dec 06, 2006 8:28 pm
by chulett
True, missed the 'into a Directory' part. Told yah I hadn't really looked at it. So... other than that, perfectly valid advice. :wink:

Posted: Wed Dec 06, 2006 9:43 pm
by Zabeerulla
Hi,

Actually the code belongs to the GetJobReport built in routine of DataStage. I have modified it to generate log of the job into a text file. Ray & Chulett, thanks for the advice & comments.