0

Our client is not interested in using any 3rd party Logger like JSON Logger or any other logger comnectors available. So is there any way to modify the default Anypoint Logging pattern in cloudhub in Json format like how a Json Logger does. Is there any way to add custom fields using default logger like api_name or flow_start_time, end_time? Currently I am creating a variable and defining required fields in a Json pattern and further configure the variable in the default logger which is a workaround and working fine but its just I was curious if this is possible in some easier way without writing any dwl?

Wiwek
  • 29
  • 4

1 Answers1

1

You can add custom variables using Mule 4.4 MDC logging feature. Note that it is not available with previous versions.

You can also request to override the default logging configuration in CloudHub, otherwise the log4j2.xml in the application is ignored, and try to use the JsonLayout. I don't recommend it though.

aled
  • 21,330
  • 3
  • 27
  • 34
  • I did not understand about raising request to overriding thing. I need to give pattern inside JsonLayout in log4j and to make it work in cloudhub I need to raise a ticket to disable cloudhub logs right? Then the log4j having json layout pattern and %MDC will work in cloudhub ? Is this what you mean by overriding or do I need to do something else for JsonLayout? Can u elaborate .Apart from these MDC, JsonLayout what do you suggest or prefer fr json logging considering safety as priority? @aled – Wiwek Apr 01 '22 at 00:12
  • Yes, I was talking about that override. I clarified that in my answer and added the link to the documentation. I remember that using JSON layout in CloudHub some years ago had some issue caused by Mule classloading, though it may work now. Personally I don't see beneficial to log in JSON format. It means dedicating more processing to format and makes logs more difficult to read. Your needs may be different so it is up to you. – aled Apr 01 '22 at 02:00
  • Maybe JSON is more readable, easy to trace that is why it is more preferred . But to achieve that the possible ways are either use 3rd party(JSON Logger) or Custom Logger Connector or JSON layout with disable Cloudhub logs as you mentioned. No easy option provided by Mulesoft for for json logging right? @aled – Karthik Apr 01 '22 at 03:51
  • Correct. It is a log4j configuration, not provided by Mule. – aled Apr 01 '22 at 09:57