how to capture job log into text file
Moderators: chulett, rschirm, roy
how to capture job log into text file
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.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Print to file
From The Director Client tool ,There print option from this u can directly print to file(.txt)
-
- Premium Member
- Posts: 210
- Joined: Wed Feb 16, 2005 7:17 am
-
- Participant
- Posts: 38
- Joined: Tue Jan 10, 2006 1:25 am
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.
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
Zabi
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 38
- Joined: Tue Jan 10, 2006 1:25 am
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
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
Zabi
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.
For example, this:
Could be replaced with this, is a little easier to read over the extra cool concatenation operator.
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.
This makes your intent clearer, in my opinion:
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.
For example, this:
Code: Select all
FileName = JobName:"_":JobStarted
FileName := Suffix
Code: Select all
FileName = JobName:"_":JobStarted:Suffix
Code: Select all
JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)
JobStarted = convert(" :-","_",DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP))
Code: Select all
JobName = DSGetJobInfo(DSJ.ME,DSJ.JOBNAME)
JobStarted = convert(" :-","_",DSGetJobInfo(DSJ.ME,DSJ.JOBSTARTTIMESTAMP))
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 38
- Joined: Tue Jan 10, 2006 1:25 am