Custom file name for Message Logging ?

How to use File logging based Message Logging policy & want to have target endpoint appended to the FileName?

meaning apiData_prxy_A.log,apiData_B.log etc (where A & B are route target).

Share some ideas on building common logging framework which can be used by other proxies.

We are using OPDK 4.15.04 on prem(FYI).

-Vinay

0 12 734
12 REPLIES 12

Former Community Member
Not applicable

Hi @vinay poreddy

how about using this for your file name element in your MessageLogging policy?

<FileName>{route.target}.log</FileName>

Seems like this should do it, let me know.

Update: The FileName element accepts a static string value.

Tried it but didn't work.Can you test it & let me know if it works?

-Vinay

@vinay poreddy Please check the scope for variable route.target . Require to add this in target flow.

I am using message logging in post client flow.Please share snapshot if you have tested?

Former Community Member
Not applicable

Hi @vinay poreddy I am simply testing is by outputting the value of the {route.target}.log in one of the response headers. I have tried adding a AssignMessage (I don't have a local deployment to test against - File logging requires an on-prem install) policy in pre-flow/response & post-flow/response of the proxy & it seems to work just fine.

It doesn't works guys..May be a bug/I might be missing something here..

In Target Post flow added Assign Message & Message logging as below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Target"> <DisplayName>Assign-Target</DisplayName>

<AssignVariable> <Name>targetURI</Name> <Ref>route.target</Ref> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>

<File async="true"> <FileName>targetURI.log</FileName> <FileRotationOptions rotateFileOnStartup="true"> <MaxFileSizeInMB>50</MaxFileSizeInMB> <MaxFilesToRetain>10</MaxFilesToRetain> <RotationFrequency unit="day">1</RotationFrequency> <FileRotationType>SIZE</FileRotationType> </FileRotationOptions> <FlushAfterEachWrite>true</FlushAfterEachWrite> <Message>{logging.Reqmessage} | {logging.Respmessage}</Message> </File>

Value gets evaluated but when message logging executes it doesn't create file name as expected.

-rw-r--r-- 1 apigee apigee 1144 Apr 4 11:54 {targetURI}.log -rw-r--r-- 1 apigee apigee 1142 Apr 4 11:57 targetURI.log bash-4.1$

-Vinay

Any suggestion on above question?

@Dino @arghya das @Anil sagar @Benjamin Goldman: Any suggestion on above question?

Depending on how you set up your proxy (like if you are using target servers set in the management service) you will have to manually set this on the request flow - as it wont be set. Turns out its only set if the proxy has target "hard coded"

That said - I have never attempted to programmatically set the file name. In my world that doesn't make sense since all i need is data out on disk for logstash to suck up and pass off to somewhere else.

In many cases you cant use variables in places you might expect to be able to - so - before banging your head against the wall just see if you can even use a variable in the file name for a message logging policy. After that you can work backwards and check the scope of the variable (or just set it - as you will probably have to)

@Benjamin Goldman:

Agree. I want apigee experts to answer if it is doable.Waiting on experts to respond.

Unfortunately we don't have any third party log managamentservices ,so till that time I want to have easy life to create basic logs based on the target for ops team.

Also share some ideas on building common logging framework which can be used by other proxies?

@vinay poreddy

In the target flow, using assign message header/javascript store the value of target.url in some dummy variable. And then use the tag as mention by @Prithpal Bhogill

Hello,

In my experience with the Message Logging policy, none of the fields except Message can accept variables.

<MessageLogging name="LogPolicy">
  <File>
    <Message>This is a test message. Message id : {request.header.messageId}</Message>
    <FileName>test.log</FileName> //Static value
    <FileRotationOptions rotateFileOnStartup="true">
      <FileRotationType>TIME_SIZE</FileRotationType> //enum 
      <MaxFileSizeInMB>10</MaxFileSizeInMB> //number
      <MaxFilesToRetain>10</MaxFilesToRetain> //number
      <RotationFrequency unit="minute">10</RotationFrequency> //number
    </FileRotationOptions>
  </File>
  <logLevel>ERROR</logLevel>  //enum
</MessageLogging>


We had run an experiment in which we would save all the values for this policy in KVMs so that we can control the logging parameters in realtime, but since we were unable to reference and access variables in those elements, we could not proceed.