AutoIt
#include <File.au3> #include <FileConstants.au3> Global $hLog _Log("testing1", "HR") ; file 1 _Log("testing2", "HR") ; file 1 _Log("testing3", "Payroll") ; file 2 _Log("testing4") ; no prefix file 3 Func _Log($sText, $sAppend = "") ; Writes script output to console, file, and command window if compiled Local $sPrefix, $sLogName = @MON & "-" & @MDAY & "-" & @YEAR & "--" & @HOUR & "-" & @MIN If $sAppend <> "" Then $sLogName = $sAppend & "-" & $sLogName ; prefix log ID when writing to multiple log files in a single script If Not $hLog Then $hLog = FileOpen(@ScriptDir & "\logs\" & $sLogName & ".log", $FO_CREATEPATH + $FO_OVERWRITE) ; open log file If $hLog = -1 Then ; confirm RW access for log file ConsoleWrite("! [ERROR] - Can't create log file" & @CR) Exit(1) EndIf EndIf Switch $sText Case StringInStr($sText, "ERROR") > 0 $sPrefix = "!" ; red Case StringInStr($sText, "WARN") > 0 $sPrefix = "-" ; orange Case StringInStr($sText, "ACTION") > 0 $sPrefix = "+" ; green Case Else $sPrefix = ">" ; blue EndSwitch ConsoleWrite($sPrefix & " " & $sText & @CRLF) ; write to console and commmand window (if compiled) _FileWriteLog($hLog, $sText) ; write to log file EndFunc ;==>_Log
what would you suggest to be able to open multiple file handles within a single script based on the $sAppend value?