Layer7 API Management

Expand all | Collapse all

Logging HTTP Request Params to custom Log Sink File

Jump to Best Answer
  • 1.  Logging HTTP Request Params to custom Log Sink File

    Posted 01-03-2019 11:08 AM

    Hi All,

     

    I am new to CA API Gateway.

     

    I am trying to create a policy fragment for logging the request parameters for the API.

     

    I am using Javascript assertion and have written the code, which is working fine for a test API. Used the documentation to get the context variables from request params perspective.

     

    On the API, I have created a Log Sink with default properties , meaning it's a file based logging.

     

    As per documentation for JS assertion, involving logger , it suggests that logged parameters can only be written to Syslog .

     

    logger.log(LOG_LEVEL.INFO, "The name from the request is: " + username); // Log to SSG logs.

     

    How can I log it into the custom log sink file?

     

    Thanks

    Milind



  • 2.  Re: Logging HTTP Request Params to custom Log Sink File
    Best Answer

    Posted 01-03-2019 11:30 PM

    Hello Milind,

     

    I was able to log messages to a custom log file from the Execute JavaScript Assertion with the Log Sink settings below:

     

     

    The log file is created in the same directory as SSG logs (/opt/SecureSpan/Gateway/node/default/var/logs).

     

    Best regards,

    Seiji



  • 3.  Re: Logging HTTP Request Params to custom Log Sink File

    Posted 01-04-2019 05:23 AM

    Thanks Seiji for the response.

     

    The classpath (com.l7tech.external.assertions.js.features.bindings.JavaScriptLogger) mentioned in the filter is for JS assertion? Can you please confirm.

     

    Also, do I need to add an Audit Detail Assertion in Policy Fragment?

     

    Regards

    Milind



  • 4.  Re: Logging HTTP Request Params to custom Log Sink File

    Posted 01-06-2019 07:28 PM

    Hi Milind,

     

    The classpath is for the logger binding object in JS assertion.

    Execute JavaScript Assertion - CA API Gateway - 9.4 - CA Technologies Documentation 

     

    No, you don't need to use any Audit Detail Assertions for the logger.log() method in JS assertion.

    The output of the logger.log() method is recorded in the SSG logs (e.g. ssg_0_0.log), not in the Audit logs.

     

    Best regards,

    Seiji



  • 5.  Re: Logging HTTP Request Params to custom Log Sink File

    Posted 01-07-2019 03:52 AM

    Thanks Seiji for the response.

     

    I removed the logger.log(), from JS Code written using assertion. The log file did not have the data created for an API. Only when I add it , I can see the log data coming into the file, of course, also in SSG log (which I want to avoid).

     

    Is there any config which I am missing?

     

    Also, I tried using the same approach for another API, to have individual log per API, but the log data for API A is written in API B.

     

    Regards

    Milind