how to capture job log into text file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
bikan
Premium Member
Premium Member
Posts: 128
Joined: Thu Jun 08, 2006 5:27 am

how to capture job log into text file

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dssiddu
Participant
Posts: 66
Joined: Mon Nov 07, 2005 10:28 pm
Contact:

Print to file

Post by dssiddu »

From The Director Client tool ,There print option from this u can directly print to file(.txt)
aakashahuja
Premium Member
Premium Member
Posts: 210
Joined: Wed Feb 16, 2005 7:17 am

Post 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.
Zabeerulla
Participant
Posts: 38
Joined: Tue Jan 10, 2006 1:25 am

Post 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.
Thanks & Regards,

Zabi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Zabeerulla
Participant
Posts: 38
Joined: Tue Jan 10, 2006 1:25 am

Post 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
Thanks & Regards,

Zabi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Zabeerulla
Participant
Posts: 38
Joined: Tue Jan 10, 2006 1:25 am

Post 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.
Thanks & Regards,

Zabi
Post Reply