« MBS FileMaker Plugin,… | Home | Calling C functions f… »

Background Log Custom function

We recently talked to a client about sending log messages out in background. You know a normal script would block the interface and we really prefer to have the user not notice it, even when the network hangs. By using CURL.PerformInBackground function, we can send the log in the background without to another server and receive it there. Whether this is your own php or python script, or you decide to pass it to the FileMaker data API or one of the AWS services doesn't matter. Just include the credentials to use with the request. And with CURL.PerformInBackground function, the transfer will happen even if FileMaker shows a dialog, performs another script or is busy for a few minutes.

 

The custom function below builds the CURL request, setups all the options and then starts it in background. FileMaker may show some dialog and block a script from running, but the custom functions runs in a few milliseconds and then the plugin can do the transfer on a background thread. We setup an expression to simply release the CURL object when it succeeds and set a script to run in case of failure. That allows us to log the failure locally with a script in FileMaker and do something about it. For older plugin versions, you may do similar with CURL.SetFinishedEvaluate and CURL.SetFinishedScript functions.

 

SendLog(JSON)

Let([

   curl = MBS("CURL.New");

   r = MBS("CURL.SetOptionURL"; curl; "https://www.your-domain.com/filemaker/log.php");

   r = MBS("CURL.SetOptionHTTPHeader"; curl; "Content-Type: application/json");

   r = MBS("CURL.SetOptionPostFields"; curl; json);

   // in case of success, just release it.

   r = MBS("CURL.SetSucceededEvaluate"; curl; "MBS(\"CURL.Release\"; $$ID$$)" );

   // in case of failure, trigger script to log error

   r = MBS("CURL.SetFailedScript"; curl; Get(FileName); "Transfer Failed" );

   // start sending in background

   sent = MBS("CURL.PerformInBackground"; curl)

]; sent)

 

Logging to a separate server helps to make sure that nobody deletes traces in logging when hacking the system. Just an extra thing to think about when you do logging in your systems. The new functions in MBS FileMaker Plugin 14.0 allow you to put in different handlers for success and failure. Please try and see if you can adapt this!

Claris FileMaker Plugin
09 01 24 - 10:58