Commits

Christoph Jüngling committed dc7acbd

clsLogfile.cls added

Comments (0)

Files changed (1)

+VERSION 1.0 CLASS
+BEGIN
+  MultiUse = -1  'True
+  Persistable = 0  'NotPersistable
+  DataBindingBehavior = 0  'vbNone
+  DataSourceBehavior  = 0  'vbNone
+  MTSTransactionMode  = 0  'NotAnMTSObject
+END
+Attribute VB_Name = "clsLogfile"
+Attribute VB_GlobalNameSpace = False
+Attribute VB_Creatable = True
+Attribute VB_PredeclaredId = False
+Attribute VB_Exposed = False
+''
+' Provide functionality to write a log file
+'
+' @author   Christoph Juengling
+'
+Option Explicit
+
+Public append As Boolean
+Private m_strLoggedText As String
+Private m_strFilename As String
+
+Private fso As Scripting.FileSystemObject
+Private file As Scripting.file
+
+Private Sub Class_Initialize()
+
+append = True
+filename = ""
+
+Set fso = New Scripting.FileSystemObject
+
+End Sub
+
+Private Sub Class_Terminate()
+
+Set file = Nothing
+Set fso = Nothing
+
+End Sub
+
+''
+' Write a line of text into the log file
+'
+' @param    text   Text
+' @author   Christoph Juengling
+'
+Public Sub WriteLine(Optional ByVal text As String = "")
+
+Const FUNCTION_NAME = "WriteLine"
+
+Dim openfor As Integer
+Dim ts As Scripting.textStream
+Dim es As tSavedError
+
+'------------------------
+
+On Error GoTo Catch
+
+If filename = "" Then RaiseProjectError ERR_FILEACCESS_ERROR, , , "No log file specified"
+
+If append Then openfor = ForAppending Else openfor = ForWriting
+Set ts = file.OpenAsTextStream(openfor)
+ts.WriteLine text
+
+m_strLoggedText = AddToList(m_strLoggedText, text, vbNewLine)
+
+'------------------------
+Final:
+On Error Resume Next
+ts.Close
+Set ts = Nothing
+
+On Error GoTo 0
+RaiseSavedError es
+Exit Sub
+
+'------------------------
+Catch:
+es = SaveError(typeName(Me), FUNCTION_NAME, Erl)
+Select Case es.number
+    Case Else
+        Debug.Print es.number, es.source, es.description
+End Select
+Resume Final
+Resume ' for test purposes only
+
+End Sub
+
+Public Property Get filename() As String
+
+filename = m_strFilename
+
+End Property
+
+Public Property Let filename(ByVal strFilename As String)
+
+Const FUNCTION_NAME = "filename"
+
+Dim es As tSavedError
+
+'------------------------
+
+On Error GoTo Catch
+
+If StrComp(m_strFilename, strFilename, vbTextCompare) <> 0 Then
+    If Not file Is Nothing Then Set file = Nothing
+    If Not fso.FileExists(strFilename) Then fso.CreateTextFile (strFilename)
+    Set file = fso.GetFile(strFilename)
+End If
+
+m_strFilename = strFilename
+m_strLoggedText = ""
+
+'------------------------
+Final:
+On Error GoTo 0
+RaiseSavedError es
+Exit Property
+
+'------------------------
+Catch:
+es = SaveError(typeName(Me), FUNCTION_NAME, Erl)
+Select Case es.number
+    Case Else
+        Debug.Print es.number, es.source, es.description
+End Select
+Resume Final
+Resume ' for test purposes only
+
+End Property
+
+Public Property Get loggedText() As String
+
+loggedText = m_strLoggedText
+
+End Property
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.