message processor log timezone

I need help in setting the timezone for the message processor logs to generate it with +00:00 format

Currently the message processor logs in the below path comes as" 2020-09-14 14:09:29,822" , where as i would need the timings to be generated as follow's "2020-09-14 14:09:29,822 +00:00"

Could some one help me on this , the log file is /opt/apigee/var/log/edge-message-processor/logs/system.log

0 1 1,079
1 REPLY 1

You can handle this with a CwC setting.

Apigee uses logback for the logging. Logback has configurable patterns for formatting. The CwC token for the logback pattern is this:

conf_logback_defaultPattern

To use this you will need to edit the file /opt/apigee/customer/application/message-processor.properties to add a line like this:

conf_logback_defaultPattern=%d{yyyy-MM-dd HH:mm:ss.SSS ZZZ} ${mdcPattern} %thread %-5level %logger{25} - %C{0}.%M\\\\(\\\\) : %msg%n

Restart the MP. (follow these instructions)

The output is like this:

2020-09-15 21:32:15.121 +0000

That's not quite what you wanted. You said you wanted a comma delimiter before the milliseconds value. And you said you wanted the timezone offset with a colon.

First problem. We can try just replacing the final dot with a comma, but the comma is a delimiter for logback. The doc for logback tells us, if we want to embed a comma in the output, then use double-quotes around the pattern string, like this %d{"yyyy-MM-dd HH:mm:ss,SSS ZZZ"}. But that doesn't work as desired, because of the CwC approach; the value is extracted from the properties file and then plopped into an XML file as the value of an attribute on an element. So we need to escape the quotes. Since the eventual destination is a logback.xml file, we should use an XML-escape sequence ( & quot;) for the escaped quote. like this:

%d{& quot;yyyy-MM-dd HH:mm:ss,SSS ZZZ& quot;}

(Remove the space in the above after the ampersands)

The result of that is

2020-09-15 21:32:15,121 +0000

...which is good. You can see the comma there, where you want it. Now, the final problem. We want +00:00 rather than +0000.

According to the logback documentation, The correct pattern to get +07:00 or similar for the timezone offset uses XXX for the timezone portion. In other words it would look like yyyy-MM-dd HH:mm:ss,SSS XXX. This does not work, because in Java, the output for UTC will never be +00:00. According to the documentation for the java SimpleDateformat class, when the timezone is UTC, the output for the XXX pattern sequence becomes "Z", Like this:

2020-09-15 21:32:15.121 Z

...which is not what you want. There is a way to partially resolve this problem: ask for the output in a particular timezone that is NOT UTC. Again, drawing on the logback documentation, there is a way to ask for the time to be expressed relative to a particular timezone, with the logback date format string. It looks like this:

& quot;yyyy-MM-dd HH:mm:ss,SSS XXX& quot;,America/Los_Angeles

(again, remove the spaces after the ampersands). The result is:

2020-09-15 14:32:15,121 -07:00

...which I think is basically what you wanted. You still cannot get +00:00, which is UTC. But you can get a number for the offset which is not UTC.

Summary of my results:

format within %d{} example time output
yyyy-MM-dd HH:mm:ss.SSS ZZZ 2020-09-15 21:32:15.121 +0000
yyyy-MM-dd HH:mm:ss.SSS XXX

2020-09-15 21:32:15.121 Z

yyyy-MM-dd HH:mm:ss,SSS XXX

2020-09-15 21:32:15

"yyyy-MM-dd HH:mm:ss,SSS XXX"

2020-09-15 21:32:15,121

& quot;yyyy-MM-dd HH:mm:ss,SSS ZZZ& quot;

2020-09-15 21:32:15,121 +0000

& quot;yyyy-MM-dd HH:mm:ss,SSS XXX& quot;,America/Los_Angeles

2020-09-15 14:32:15,121 -07:00