VBScript → Lua
This function logs some details into a given log (text) file.
Please see the Introduction chapter for some usage instructions.
' FileOpen iomode Values Const fsoForReading = 1 ' Open a file for reading only. Const fsoForWriting = 2 ' Open a file for writing only. Const fsoForAppending = 8 ' Open a file and write to the end of the file. Const fsoDontCreateIfNotExist = False Const fsoCreateIfNotExist = True Const fsoTristateUseDefault = -2 ' Opens the file by using the system default. Const fsoTristateTrue = -1 ' Opens the file as Unicode. Const fsoTristateFalse = 0 ' Opens the file as ASCII. Const LogFormat = """%NUMBER%"",""%NAME%"",""%TIMESTAMP%""" '---------------------------------------------------------------- ' Function LogCallIntoTextFile ' ' Logs details of the current call into a text file. ' Line format: "Number","Name","Timestamp" ' ' Parameter: ' sFileName name of logfile (incl. path) ' ' Return: ' boolean true - log created, false - error creating log '---------------------------------------------------------------- Function LogCallIntoTextFile ( sFileName ) PBXScript.OutputTrace "-----------> LogCallIntoTextFile ( " & sFileName & ")" On Error Resume Next Dim bReturn bReturn = False Dim fso, file, sLine ' create FileSystemObejct Set fso = CreateObject("Scripting.FileSystemObject") ' open text file Set file = fso.OpenTextFile(sFileName, fsoForAppending, fsoCreateIfNotExist, fsoTristateFalse) if Err <> 0 then PBXScript.OutputTrace "Error opening log file!" PBXScript.OutputTrace Err & ": " & Err.Description else ' create log line sLine = LogFormat sLine = Replace(sLine, "%NUMBER%", PBXCall.CallingPartyNumber) sLine = Replace(sLine, "%NAME%", PBXCall.CallingPartyName) sLine = Replace(sLine, "%TIMESTAMP%", Now) PBXScript.OutputTrace "sLine = " & sLine ' write (append) log data to file file.WriteLine(sLine) file.Close() Set file = Nothing bReturn = True end if Set fso = Nothing LogCallIntoTextFile = bReturn PBXScript.OutputTrace "bReturn = " & bReturn PBXScript.OutputTrace "<----------- LogCallIntoTextFile" End Function
This function makes use of the Server Script API functions PBXCall.CallingPartyNumber and PBXCall.CallingPartyName for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.
![Tom Wellige](http://content.invisioncic.com/r255538/monthly_2020_04/facebook2.thumb.png.7201b63ad83065920f23d2478c4a838f.png)
By Tom Wellige
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now