Snippets

Sean Bamforth Quick Logging

Created by Sean Bamforth last modified
Global_Variable Integer ghlogfile 
Object oSimpleLog is a cObject
    Property String psPrivate.LogName 
    
    Procedure Set logfile String sName 
        String sFolder 
        Get psHome of (phoWorkspace(oApplication)) to sFolder 
        If ((Right(sFolder,1))<>"\") Append sFolder "\"
        Append sFolder sName 
        Set  psPrivate.LogName to sFolder 
    End_Procedure
    
    Function logfile Returns String 
        String sProgname 
        String sLogFile
        If ((psPrivate.LogName(Self))="") Begin 
            Move (GetApplicationName(ghoApplication)) to sProgName 
            Move (sProgName+".log") to sLogFile
            Set logfile to sLogFile             
        End
        Function_Return ( psPrivate.LogName (Self))
    End_Function
    
    Procedure doLog String sText 
        Integer iCH 
        DateTime dtNow
    
        Move (CurrentDateTime()) to dtNow
        Move ("["+(String(dtNow)) +"] "+  sText) to sText 
        
        Get Seq_New_Channel to iCH 
        Append_Output channel iCH (logfile(Self)) 
        Writeln channel iCH sText 
        Close_Output channel iCH 
        Send Seq_Release_Channel iCH 
    End_Procedure
    
    Move (Self) to ghlogfile
End_Object

Procedure QuickLog Global String sMessage 
    Send doLog to ghLogFile sMessage  
End_Procedure

Comments (0)