Home Knowledge Articles Series 7 Macro for scanning Transformer logfiles
Follow us on Twitter


Countries

50.1%United States United States
7.6%India India
7%United Kingdom United Kingdom
5.1%Australia Australia
4.8%Canada Canada

Visitors

Today: 30
Yesterday: 111
Last Week: 3353
This Month: 9182
Last Month: 16191
Total: 382835


Macro for scanning Transformer logfiles PDF Print E-mail
(1 vote, average 5.00 out of 5)
Written by Martijn Christenhusz   
Wednesday, 06 May 2009 20:21

When you have a huge number of cubes, it takes a lot of time to check all the transformer logfiles. This macro scans the c:\temp directory for files with a log extension. All the found log files are scanned and when a TR, Warning or Error text is found the line is copied to a c:\temp\README.txt file.

Copy this code and paste it in CognosScript editor. Change the directory path where your transformer log files are located. Save the file and run the macro.

 '****************************************************************************************
' Date:
' Name: CUBE_BUILD_NOTIFY
' Author: Administrator
'
' Description: This macro parses Transformer logfiles for user-defined text strings
' and write the error to c:\temp when the strings occur.
'
'****************************************************************************************

Option Explicit

Dim LogFileNo  As Integer
Dim FileNo     As Integer
Dim FileLine   As String

Dim AppPath  As String
Dim iniFile  As String
Dim LogPath  As String

Dim TransformerLogFile  As String
Dim ScriptLogFile           As String
Dim CurrentLogFile        As String
Dim CRLF                     As String

' Location of the logfile to be scanned.
const REPORTDIRECTORYPATH  = "C:\Temp"

Declare Sub Log_Info(Msg_In As String)

' -----------------------------------------------------------------------------------------
Sub Main ()

Dim FileName            As String
Dim ReportDirectory  As String

On Error Goto ErrorTrap

CRLF = Chr$(13) & Chr$(10)
 
  LogPath = "C:\TEMP"
 
  'setup connection to output logfile Cube_Build_Notify_Script.log
  ScriptLogFile = LogPath  & "\README.txt"
  LogFileNo = Freefile()
  Open ScriptLogFile for Output As LogFileNo
 
  Print #LogFileNo, "CUBE_BUILD_NOTIFY Script " & Date() & " " & Time() & CRLF
  Print #LogFileNo, "Transformer Log File: " & ScriptLogFile & CRLF
  
  FileNo = FreeFile()
    
  ReportDirectory = REPORTDIRECTORYPATH & "\*.log"

  'Set directory to scan
  FileName= Dir (ReportDirectory)

Do While FileName<>"" 
   CurrentLogFile = REPORTDIRECTORYPATH & "\" & FileName
   Open CurrentLogFile For Input As FileNo ' open Transformer log file       
     Print #LogFileNo, "<<< " & CurrentLogFile & " gestart... >>>"    
     Do While Not Eof(FileNo)             
    
        Line Input #FileNo, FileLine       ' read each line in log file
                    
        If InStr(1, FileLine, "Error:", 1) > 0 Then      
           call Log_Info(FileLine)
        End If 
                                      
        If InStr(1, FileLine, "Warning:", 1) > 0 Then      
           call Log_Info(FileLine)
        End If
                       
        If InStr(1, FileLine, "(TR", 1) > 0 Then      
           call Log_Info(FileLine)
        End If  
     Loop 
    
     Print #LogFileNo, "<<< " & CurrentLogFile & " afgerond >>>"
     Close FileNo ' close Transformer log file
       
   FileName=Dir
Loop
    
     call Log_Info("End CUBE_BUILD_NOTIFY Script ")  
     Exit Sub
        
errorTrap:
   Call Log_Info("Error " & Str(Err) & ": " & Error$(Err))
   Close #LogFileNo
        
End Sub 'main

'--------------------------------------------------------------------------------------------
Sub Log_Info(Msg_In as String)

  Print #LogFileNo, Date() & "-" & Time() & ": " & Msg_In
 
End Sub

'--------------------------------------------------------------------------------------------

Comments

Please login to post comments or replies.
Last Updated on Saturday, 30 January 2010 11:30
 
 

Login

For more content en features!



CogKnowHow Newsletter

Season's Greetings


Receive HTML?

Polls

How many users are working on your Cognos environment?