1

I am building a Mulesoft/Anypoint app for deployment on Cloudhub, and for diagnostic purposes want to be able to determine (from within the app) whether it is running on Cloudhub or in Anypoint Studio on my local development machine:

  • On Cloudhub, I want to use the Cloudhub connector to create notifications for exceptional situations - but using that connector locally causes an exception.
  • On my local machine, I want to use very verbose logs with full dumping of the payload (#[message.payloadAs(java.lang.String)]) but want to use much more concise logging when on Cloudhub.

What's the best way to distinguish the current runtime? I can't figure out any automatic system properties that expose this information.

(I realize the I could set my own property called something like system.env=LOCAL and override it with system.env=CLOUDHUB for deployment, but I'm curious if the platform already provides this information in some way.)

Benj
  • 1,853
  • 4
  • 18
  • 27

1 Answers1

1

As far as I can tell the best approach is to use properties. The specific name and values you use doesn't matter as long as you're consistent. Here's an example:

In your local dev environment, set the following property in mule-app.properties:

system.environment=DEV

When you deploy to Cloudhub, use the deployment tool to change that property to:

system.environment=CLOUDHUB

Then in your message processors, you can reference this property:

<logger 
    message="#['${system.environment}' == 'DEV' ? 'verbose log message' : 'concise log message']"        
    level="ERROR"
    doc:name="Exception Logger"
/>
Benj
  • 1,853
  • 4
  • 18
  • 27