Script to search error string

Hi experts,
I´m working on a script to monitor logs that contains a specific string, it is working fine, but now I need that it shows the date and hour when it finds an error on the message, also, it must include all the text of the error.
Can you help me with it please?
This is the script:

'/file: [required] This is the UNC location for the file to be searched.
'	${Date} is a wildcard you can put anywhere in the filename to indicate the datestamp(current date) as part of the filename. 
'	* ${Date} must be used with strDateFormat!!
'	Example: /file:"//myserver/myshare$/myfile.txt" or /file:"${IP}/myshare/myfile.txt"
'/search: [required] This is the string to be searched for in the filename.\
'Example: /search:"error" or /search:"failed"
'DateFormat: [only required if used with ${Date} in file] This is the configuration for the format your datestamps are in.
strDateFormat = "yyyy_mm_dd"
'	Usage: 
'	yyyy - 4 digit year
'	yy - 2 digit year
'	mm - 2 digit month
'	m - 1 digit month
'	dd - 2 digit day
'	d - 1 digit day
'	Seperators: "-", ".", "_", "/"
'Example: strDateFormat = "mm-dd-yyyy" or strDateFormat = "yy_m_d"
'FailIf: [optional] Specify to fail the check if the search string is found or not found
strFailIf = "found"
'	Usage:
'	found
'	not found
'Example: strFailIf = "found" or strFailIf = "not found"
strFileName = Wscript.Arguments.Named("file") 'Get file name from argument
If strFileName = "" Then
    Wscript.Echo "Message: You must specify a File Name like this: /file:""blah.txt"""
End If

strSearch = Wscript.Arguments.Named("search") 'Get search string form argument
If strSearch = "" Then
    Wscript.Echo "Message: You must specify a string to search for like this: /search:""ERROR"""
End If

If strFailIf="" Then strFailIf="found" End If
If (strFailIf="found") Then
ElseIf (strFailIf="notfound" or strFailIf="not found") Then
	Wscript.Echo "Message: ERROR, set strFailIf"
End If	

yyyy = Datepart("yyyy",Date())
yy = Right(yyyy, 2)
m = Datepart("m",Date())
mm = Right("0" & m, 2)
d = Datepart("d",Date())
dd = Right("0" & d, 2)

If (InStr(1,strFileName,"${Date}",1) <> 0) Then
	If (InStr(1,strFileName,"${Date}",1) <> 0 AND strDateFormat <> "") Then
		strDateFormat = replace(strDateFormat, Space(1), " & Space(1) & ")
		strDateFormat = replace(strDateFormat, "_", " & ""_"" & ")
		strDateFormat = replace(strDateFormat, "/", " & ""/"" & ")
		strDateFormat = replace(strDateFormat, "-", " & ""-"" & ")
		strDateFormat = replace(strDateFormat, ".", " & ""."" & ")
		strFileName = Replace(strFileName,"${Date}",eval(strDateFormat),1,-1,1)
		Wscript.Echo "Message: Error with ${Date} and strDateFormat. Please review instructions at top of script."
	End If
End If

strPattern = strSearch

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists("temp") Then
End If

PrevLogFile =  "temp\" & strSearch & "-" & mm & "_"  & dd-1 & "_"  & yyyy & ".txt"
If objFSO.FileExists(PrevLogFile) Then
	set objPrevLogFile = objFSO.GetFile(PrevLogFile)
End If

PreviousFinds = 0
LogFile = "temp\" & strSearch & "-" & mm & "_"  & dd & "_"  & yyyy & ".txt"
If objFSO.FileExists(LogFile) Then
	Set objLog = objFSO.OpenTextFile(LogFile,1, True)

	If (IsEmpty(objLog) = True ) Then PreviousFinds = 0 End If
PreviousFinds = objLog.ReadAll
End If

If objFSO.FileExists( strFileName ) Then
  Set objFile = objFSO.GetFile(strFileName)
  If( IsEmpty( objFile ) = True ) Then
      WScript.Echo "Message: OBJECT NOT INITIALIZED"
      WScript.Echo "Statistic: 0"
    End If
    WScript.Echo "Message: The file """ & strFileName & """ was not found!<BR>This could indicate that the file does not exist or you do not have the correct credentials for monitoring. <BR>" 
    WScript.Echo "Statistic: 0"
End If

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = strPattern
objRegEx.IgnoreCase = True
Set objReadFile = objFSO.OpenTextFile(strFileName, ForReading)
Do Until objReadFile.AtEndOfStream
    strSearchString = objReadFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)  
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches   
			If int(x) > int(PreviousFinds) Then		
				Wscript.Echo "Statistic: " & PreviousFinds+1 
				Wscript.Echo "Message: New search for """ & strSearch & """ was found: " & strSearchString
					Set objLog = objFSO.OpenTextFile(LogFile, 2, True)
			End If
    End If
If int(x) >1 Then
	Wscript.Echo "Statistic: " & PreviousFinds
    Wscript.Echo "Message: New search for """ & strSearch & """ was found, but previous searches did find """ & strSearch & """."
End If
Wscript.Echo "Statistic: " & PreviousFinds 
Wscript.Echo "Message: Search for """ & strSearch & """ was not found."

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, for the date, just add
Now & ....

to the start of your output.  For example, change
                              objLog.WriteLine(Now & " - "  & PreviousFinds+1)

For the return of the entire error, isn't that what has been output by strSearchString, assuming the error is on the entire line?



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.