Option Public Option Declare Use "../../../src/VoltScriptLogging" UseVSE "*StreamVSE" UseVSE "*OSUtilsVSE" Sub Initialize Dim streamWriter as New LogWriterStream("StreamLogWriter", LOG_DEBUG, LOG_ERROR, "{{LEVELNAME}}: {{MESSAGE}}") Call globalLogSession.addLogWriter(streamWriter) Call globalLogSession.createLogEntry(LOG_INFO, "Here's a log entry", "", Nothing) Call globalLogSession.createLogEntry(LOG_ERROR, "Error encountered", "Here's a logged error", Nothing) Call globalLogSession.createLogEntry(LOG_DEBUG, "Debug message", "Here's a debug message", Nothing) End Sub Class LogWriterStream as BaseLogWriter Private logDir_ as String Private logFilePath_ as String Private logStream_ as Stream Sub New(label as String, minLevel as Integer, maxLevel as Integer, formatter as String) ' this will write the log entries to a subdirectory called logs in the current directory logDir_ = CurDir() & "/logs" End Sub Sub initializeLog() Dim rbool as Boolean Dim myOS as New OSUtils ' make sure the logStream object is loaded, and the file path is set appropriately Set logStream_ = New Stream rbool = myOS.makeDirectories(logDir_) ' ensures the log directory exists If not rbool Then Error 1001, "Error creating log directory (" & logDir_ & ")" logFilePath_ = logDir_ & "/" & "log_" & Format(Now, "YYYYMMDD-hhmmss") & "_" & createUUID() & ".log" Call logStream_.open(logFilePath_, "UTF-8") End Sub Public Sub outputLogEntryMessage(message as String) ' this writes the log entry to the stream every time a log entry is added to the log Call logStream_.writeText(message, EOL_LF) End Sub Public Sub terminateLog() ' this closes the stream and writes the logs to the file on disk Call logStream_.close() End Sub End Class