Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Time Stamp on Log file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59812
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Time Stamp on Log file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Time Stamp on Log file - 5/5/2008 1:04:43 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hey All

I have script to find an "ERROR" in my log file, but am thinking to put a time stamp on that error message

here is my script


********************************************************************

Const csDir   = "C:\log"
Const csExt   = "txt"
Const csFind  = "ERROR"
Const csLog   = "c:\Log\fail.log"
Dim oFS       : Set oFS       = CreateObject( "Scripting.FileSystemObject" )
Dim oLog      : Set oLog      = oFS.CreateTextFile( csLog, True )
Dim oFile
For Each oFile In oFS.GetFolder( csDir ).Files
    If 0 = StrComp( csExt, oFS.GetExtensionName( oFile.Name ), vbTextCompare ) Then
       grepSub03 oFile, csFind, oLog
    End If
Next
oLog.Close
'WScript.Echo oFS.OpenTextFile( csLog ).ReadAll
Sub grepSub03( oFile, csFind, oLog )
Dim oTS       : Set oTS       = oFile.OpenAsTextStream()
Dim nLine     : nLine         = 0
Dim sLine
Do Until oTS.AtEndOfStream
   nLine = nLine + 1
   sLine = oTS.ReadLine()
   If 0 < InStr( sLine, csFind ) Then
      oLog.WriteLine oFile.Name & " " & nLine & " " & sLine
   End If
Loop
oTS.Close
End Sub

*******************************************************************************



My log file look like


**************************** START PROCESS LOG FOR: *************************
Sat 04/26/2008
05:16 AM

"-----------> \BUY.TXT File Exists...Processing"
"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT to K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\WORK\BUY.TXT"

ERROR Verify - J:\BUY.TXT
"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT to J:\BUY.TXT"

"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY_20080426_00516.TXT"

"Moved K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY_20080426_00516.TXT to K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\History\BUY_20080426_00516.TXT"
***************************** END PROCESS LOG  ******************************
**************************** START PROCESS LOG FOR: *************************
Tue 04/29/2008
05:16 AM
"-----------> \BUY.TXT File Exists...Processing"
"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT to K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\WORK\BUY.TXT"

"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT to J:\BUY.TXT"

"Copied K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY.TXT K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY_20080429_00516.TXT"

"Moved K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\BUY_20080429_00516.TXT to K:\EDITPS\EDITPS\MMIS\OUTBD_APPL\INBD_DB_FILES\History\BUY_20080429_00516.TXT"
***************************** END PROCESS LOG  ******************************



OutPut :

My existin script write a log file like

PROMISLoad_LogFile.TXT 12268 ERROR Verify - J:\BUY.TXT


I would to make an log file like this

PROMISLoad_LogFile.TXT 12268 ERROR Verify - J:\BUY.TXT  Sat 04/26/2008

Thanks in Advance

Ashok

 
 
Post #: 1
 
 RE: Time Stamp on Log file - 5/5/2008 1:27:37 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
Ok, so all you need to do is as you are parsing the log, look for dates. Whenever you find one store it in a variable. THen when you find the error just stick that variable on the end of the line that you write.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ashok_ganeshs)
 
 
Post #: 2
 
 RE: Time Stamp on Log file - 5/5/2008 3:02:25 AM   
  ehvbs

 

Posts: 1843
Score: 46
Joined: 6/22/2005
From: Germany
Status: offline
Hi ashok_ganeshs,

nice to meet you again!

try:


      

Good luck!

ehvbs

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Time Stamp on Log file - 5/5/2008 7:47:40 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hey Ehvbs,

Please to meet you again, i saw ebgreen reply,i haven't try yet (got a jet lock, came back from vacation today) so thinking to start tomm.

Eventually got yours thanks Ehvbs.

Thanks Again
Ashok

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Time Stamp on Log file - 5/6/2008 1:30:39 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Ehvbs

Okie here is the out put


Line No: 15197 Messg: ERROR Verify - J:\BUY.TXT  Date:??? ??/??/????
Line No: 15718 Messg: ERROR Verify - J:\BUY.TXT  Date:??? ??/??/????

Sdate value is "??? ??/??/????" that's why ,but i don't understand what is the use of that  constant value (??? ??/??/????)

Thanks
Ashok

(in reply to ashok_ganeshs)
 
 
Post #: 5
 
 RE: Time Stamp on Log file - 5/6/2008 1:37:35 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
The :??? ??/??/???? is simply giving an initial value for the variable. Then the variable should be subsequently populated by dates that it finds in the file. If you are getting :??? ??/??/???? in your output then I suspect the regex pattern needs to be tweaked a little.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ashok_ganeshs)
 
 
Post #: 6
 
 RE: Time Stamp on Log file - 5/6/2008 1:57:40 AM   
  ehvbs

 

Posts: 1843
Score: 46
Joined: 6/22/2005
From: Germany
Status: offline
Hi ashok_ganeshs,

As ebgreen already said, the output of the default/initial value of sDate indicates
that

  If reDate.Test( sLine ) Then

never matched. As I tested my code with your sample:

**************************** START PROCESS LOG FOR: *************************
Sat 04/26/2008
05:16 AM

I'm (a bit) surprised. On second thought, copy & paste to and from the forum may
mess up whitespace/lineendings. Try to make the pattern less strict:

  reDate.Pattern = "^\w+ \d{2}/\d{2}/\d{4}$" ' eg Sat 04/26/2008
==>
  reDate.Pattern = "^\w+ \d{2}/\d{2}/\d{4}"\s*$ ' allow only whitespace before EOL after the 4 digit year

Good luck!

ehvbs

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Time Stamp on Log file - 5/6/2008 3:33:32 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thanks Ebgreen and Ehvbs,

I was trying to tweak the regexp but not in success,so thought to change the reg exp like below

Sub grepSub03( oFile, csFind, oLog )
Dim reDate    : Set reDate    = New RegExp
reDate.Pattern="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d"  'Eg:  04/26/2008
Dim sDate     : sDate         = "??? ??/??/????"
Dim oTS       : Set oTS       = oFile.OpenAsTextStream()
Dim nLine     : nLine         = 0
Dim sLine
oLog.WriteLine oFile.Name
Do Until oTS.AtEndOfStream
   nLine = nLine + 1
   sLine = oTS.ReadLine()
   If reDate.Test( sLine ) Then
         sDate = sLine
     
   End If
   If 0 < InStr( sLine, csFind ) Then
      oLog.WriteLine "Line No:" &" " & nLine &" "&"Messg: " & sLine & " " &" Date:" & sDate
     
   End If
Loop

oTS.Close
End Sub


OutPut:

Line No: 12268 Messg: ERROR Verify - J:\BUY.TXT  Date:Wed 03/12/2008
Line No: 15197 Messg: ERROR Verify - J:\BUY.TXT  Date:Sat 04/26/2008
Line No: 15718 Messg: ERROR Verify - J:\BUY.TXT  Date:Tue 05/06/2008


Thanks Again Ehvbs and Ebgreen

Ashok





(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Time Stamp on Log file - 5/8/2008 11:50:56 PM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Ehvbs and Ebgreen,

Am trying to tweak this script little bit more like below

right now the scripts find the " ERROR" based on dates in the log file but am trying to modify like find "ERROR"  only in Today's Date

If error is found then am writing error message

Eg:Line No: 15718 Messg: ERROR Verify - J:\BUY.TXT  Date:Tue 05/06/2008

If not "NO ERROR FOUND"

here is my whole idea,when start modify the script like this

Sub grepSub03( oFile, csFind, oLog )
Dim reDate    :Date
Dim sDate 
Dim oTS       : Set oTS       = oFile.OpenAsTextStream()
Dim nLine     : nLine         = 0
Dim sLine
oLog.WriteLine oFile.Name
Do Until oTS.AtEndOfStream
  nLine = nLine + 1
  sLine = oTS.ReadLine()
  If reDate.Test( sLine ) Then
        sDate = sLine
    
  End If
  If 0 < InStr( sLine, csFind ) Then
     oLog.WriteLine "Line No:" &" " & nLine &" "&"Messg: " & sLine & " " &" Date:" & sDate
    
  End If
Loop

oTS.Close
End Sub


It throws "Object Required" error message...Thanks for your help in Advance.


Thanks
Ashok

(in reply to ashok_ganeshs)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Time Stamp on Log file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts