Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing to a log
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply


Messages In This Thread
Printing to a log - by dravilis - 11-21-2012, 10:48 PM
RE: Printing to a log - by Ankesh - 11-22-2012, 09:30 AM
RE: Printing to a log - by pradeep singh - 11-22-2012, 01:02 PM
RE: Printing to a log - by vinod123 - 11-22-2012, 05:25 PM
RE: Printing to a log - by dravilis - 12-04-2012, 05:03 AM
RE: Printing to a log - by elango87 - 12-06-2012, 06:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Grab multiple line data from log file haziqwebs 0 1,792 10-19-2016, 01:28 PM
Last Post: haziqwebs
  How to print value in QTP Log using .vbs kalyaniR 1 3,366 10-25-2013, 04:32 PM
Last Post: ssvali
  To view log files in QTP sheetal 5 16,759 10-08-2013, 02:27 PM
Last Post: Gurpreet
  Hep to create yahoo log in function. jinnah1978 1 2,851 02-23-2012, 10:24 AM
Last Post: inborntester
  Log in problem JeanFrederique 1 2,070 10-20-2009, 01:38 PM
Last Post: Tarik Sheth

Forum Jump:


Users browsing this thread: 1 Guest(s)