Jump to content
  • LogCallIntoTextFile()


    Lua   → VBScript


    This function logs some details into a given log (text) file.

    Please see the Introduction chapter for some usage instructions.


    Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted.


    local 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 .. " )")
        local bReturn = false
        local sLine   = ""
        local oFile = io.open(sFileName, "a") -- append mode
        if oFile then
            -- create log line
            sLine = LogFormat
            sLine = StringReplace(sLine, "#NUMBER#",    PBXCall.CallingPartyNumber())
            sLine = StringReplace(sLine, "#NAME#",      PBXCall.CallingPartyName())
            sLine = StringReplace(sLine, "#TIMESTAMP#", PBXUser.Now())
            PBXScript.OutputTrace ("sLine = " .. sLine)
            -- write (append) log data to file
            bReturn = true
            PBXScript.OutputTrace ("Error opening log file!")
        PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
        PBXScript.OutputTrace ("<----------- LogCallIntoTextFile")
        return bReturn


    This function makes use of the Server Script API functions PBXCall.CallingPartyNumber()PBXCall.CallingPartyName() and PBXUser.Now() for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file. It also uses the GSE build-in helper function StringReplace() to format the log data.


    You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file.


    Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Files\logfile.txt" you have to pass "C:\\Files\\logfile.txt".



    Tom Wellige


    User Feedback

    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.