home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: clsLogging.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Logging Class
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes: Creates appliation log files
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared and turn off script error messages unless in DEBUG mode
- ' ~~~
- Option Explicit
-
- Class Logging
- ' ~~~
- ' ~~~ declare variables and constants
- ' ~~~
- Dim oLogFile, sLogFileName, sLogFileNameBAK, bAppend, bBackup, bTimeStamp
-
- ' ~~~
- ' ~~~ public methods & properties
- ' ~~~
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Property: Append
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Determines if the log file is appended or overwritten
- ' *** Default value = False, overwrite
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Property Get Append
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Append = bAppend
- End Property
-
- Public Property Let Append(bValue)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- If VarType(bValue) = vbBoolean Then
- bAppend = bValue
- End If
- End Property
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Property: Backup
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Determines if and old log file is backed up (renamed .bak)
- ' *** Default value = True
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Property Get Backup
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Backup = bBackup
- End Property
-
- Public Property Let Backup(bValue)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- If VarType(bValue) = vbBoolean Then
- bBackup = bValue
- End If
- End Property
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Property: TimeStamp
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Determines if a timestamp is added to the log entries
- ' *** Default value = True
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Property Get TimeStamp
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- TimeStamp = bTimeStamp
- End Property
-
- Public Property Let TimeStamp(bValue)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- If VarType(bValue) = vbBoolean Then
- bTimeStamp = TimeStamp
- End If
- End Property
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Open
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Opens a new log file, backing up the old one if appropriate
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Sub Open(sValue)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- ' ~~~ store the logfile name
- sLogFileName = sValue
- sLogFileNameBAK = Left(sLogFileName, Len(sLogFileName)-4)
-
- ' ~~~ if old log file exists and we want to back it up
- If oFso.FileExists(sLogFileName) and bBackup Then
- ' ~~~ if backup already exists delete it
- If oFso.FileExists(sLogFileNameBAK & ".bak.log") Then
- Call oFso.DeleteFile(sLogFileNameBAK & ".bak.log", True)
- End If
-
- ' ~~~ backup current log file
- Call oFso.MoveFile(sLogFileName, sLogFileNameBAK & ".bak.log")
- End If
-
- ' ~~~ if old log file exists and we want to append to it
- If oFso.FileExists(sLogFileName) and Not(bAppend) Then
- Call oFso.DeleteFile(sLogFileName, True)
- End If
-
- ' ~~~ Open or Create log file
- ' ~~~ sLogFileName : Log file name
- ' ~~~ 8 : is for appending
- ' ~~~ True : Creates the file if not exists
- ' ~~~ -1 : for Unicode support
- Set oLogFile = oFso.OpenTextFile(sLogFileName, 8, True , -1)
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Close
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Closes a new log file
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Sub Close
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- oLogFile.Close
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Write
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Writes a line to a log file
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Sub Write(sLogFileEntry)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- If bTimeStamp Then
- oLogFile.Write(Now()) & " : "
- End If
- oLogFile.WriteLine(sLogFileEntry)
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: View
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Displays the log file in notepad
- ' *** ------------------------------------------------------------------------------
- ' ***
- Public Sub View
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Call oShell.Run("notepad.exe " & sLogFileName, 1, False)
- End Sub
-
-
- ' ~~~
- ' ~~~ private methods, these routines must not be called directly
- ' ~~~
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Class_Initialize
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Used internally by the class when it is created.
- ' *** Declared as private because it must not be called directly.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Sub Class_Initialize
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- ' ~~~ set default values of properties
- bAppend = False
- bBackup = True
- bTimeStamp = True
-
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Class_Terminate
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Used internally by the class when it is destroyed.
- ' *** Declared as private because it must not be called directly.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Private Sub Class_Terminate
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- End Sub
- End Class
-