Micro Focus QTP (UFT) Forums
Printing to a log - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Printing to a log (/Thread-Printing-to-a-log)



Printing to a log - dravilis - 11-21-2012

I need to print a message to the log. Have tried write, print, msgbox. I don't want it coming up as a pop up. Want it to print to the log. Thanks in advance.


RE: Printing to a log - Ankesh - 11-22-2012

Using print will not give any pop up. It will send the message to print log.


RE: Printing to a log - pradeep singh - 11-22-2012

You can minimize it through coding and also later export its result to text file.


RE: Printing to a log - vinod123 - 11-22-2012

Use Reporter Statement if you want to see in log

Reporter.ReportEvent 0, "Object Name", "write the message which you want to see in the result"

0 for micpass
1 for micwarning
2 for micfail


RE: Printing to a log - dravilis - 12-04-2012

Thanks Pradeep. That worked well.


RE: Printing to a log - elango87 - 12-06-2012

Below is the code for creating the log file,
It will update the date and time followed by the message. Later it can be used for analysis.

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Function to write a log file>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'This function is used to create logs
'The log file will be stored with filename as "Logfile.log" by default
'If the log file is present in the path specified, it will be updated else it will be created.
'StrTitle -> Used to give the Title for the log. Eg: Test
'StrMessage -> The message which needs to be sent
Usage: Writetolog("Test", "This is a test")
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Code:
Function Writetolog(StrTitle, StrMessage)
Dim objFS, Logfilepath, ObjFile
Set objFS = CreateObject("Scripting.FileSystemObject")
Logfilepath = Pathofthefolderwherelogfileshouldbestored & "Logfile.log" 'Enter the log file path here
If objFS.FileExists(Logfilepath) Then
        Set objFile = objFS.OpenTextFile(Logfilepath,8,False)
    Else
        objFS.CreateTextFile Logfilepath,True
        Set objFile = objFS.OpenTextFile(Logfilepath,8,False)
End If

objFile.Write "[" & Date &"]" & "[" & Time & "][" & StrTitle &"][" & StrMessage & "]" &vbcrlf

objFile.Close
Set objFile = Nothing
Set objFS = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hope this helps.

Let me know in case of any questions.

Thanks,
Elango