unable to log response body to Message logging policy

Hi,

I'm trying to log response body using Message Logging policy. i have implemented the same using below links

https://community.apigee.com/articles/14798/log-messages-into-loggly.html and

https://community.apigee.com/questions/18906/messagelogging-to-loggly.html

but i am not able to attach response content/error content to the message logging policy.

below is the message logging policy and java script policy i used and attached is the trace outputs for 200 and 401 codes for your reference.

message logging policy.

<MessageLogging name="PostClientFlowAX">
  <DisplayName>PostClientFlowAX</DisplayName>
  <Syslog>
    <Message>[xxx-xxxxxxxxx@41058 tag="{organization.name}.{apiproxy.name}.{environment.name}"] {'logResponse'} </Message>
    <Host>logs-01.loggly.com</Host>
    <Port>514</Port>
  </Syslog>
</MessageLogging>

javascript policy.

context.setVariable('logResponse', context.getVariable("response.content"))

but i am not able to log response content.Request your suggestion here.

regards,

Ramakrishna

0 3 1,106
3 REPLIES 3

It sure looks like your message includes {'logResponse'} (with single quotes surrounding the word logResponse.

I think you want {logResponse} - no single quotes.

NO:

  <Syslog>
    <Message>[xxx-xxxxxxxxx@41058 tag="{organization.name}.{apiproxy.name}.{environment.name}"] {'logResponse'} </Message>
    <Host>logs-01.loggly.com</Host>
    <Port>514</Port>
  </Syslog>

YES:

  <Syslog>
    <Message>[xxx-xxxxxxxxx@41058 tag="{organization.name}.{apiproxy.name}.{environment.name}"] {logResponse} </Message>
    <Host>logs-01.loggly.com</Host>
    <Port>514</Port>
  </Syslog>


@Dino

Thanks for your quick response.

As suggested, i removed single quote and fired requests.

For 200 OK responses, message logging is working fine as we have set java script and set response.content to logresponse and same logresponse we are using in message logging policy

javascript policy used

context.setVariable('logResponse', context.getVariable("response.content"))

message logging policy used;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MessageLogging async="false" continueOnError="false" enabled="true" name="PostClientFlowAX">
<DisplayName>PostClientFlowAX</DisplayName>
<Syslog>
<Message>[87c0e662-5e54-4111-b11a-aa85c42b2cac@41058 tag="{organization.name}.{apiproxy.name}.{environment.name}"] {logResponse} </Message>
<Host>logs-01.loggly.com</Host>
<Port>514</Port>
</Syslog>
</MessageLogging>

But for 401 error code scenario: I have added raise fault Policy as below.As i am using response content here.when a fault is raised it is skipping java script policy and post client flow message logging policy is executed which leads to issue because in message logging policy we used logresponse(which we set using javascript policy from response.content to logResponse).But when javascript policy is not executed it remains as response.content which leads to issue in message logging policy.

Request you to help me in sorting this.Attached trace session for 200 Ok and 401 error code.trace-1507803884017.zip

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Raise-Fault">
<DisplayName>Raise Fault</DisplayName>
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="application/xml"> {response.content} </Payload>
<StatusCode>401</StatusCode>
<ReasonPhrase/>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

regards,

ramakrishna

yes I understand.

OK, there are a couple possible approaches here.

  1. Don't use {logResponse}. If at all possible, use {response.content} in the message logging policy
  2. Set {logResponse} in the flow, just before calling RaiseFault

I'm sure there are other approaches. It's a matter of arranging the logic and flow correctly.