MessageLogging timestamp format

Hi,

When working with the MessageLogging policy, how do you change the timestamp format to for example YYYY-MM-DD etc..instead of this: "system.timestamp":"1532413540669" ?

So far by reading the documentation I have not found this setting.

This is what I have in my policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MessageLogging async="false" continueOnError="false" enabled="true" name="Message-Logging-1">
    <DisplayName>Message Logging-1</DisplayName>
    <File>
        <Message>
            {
                "system.timestamp":"{system.timestamp}",
                "environment.name":"{environment.name}",
                "apiproxy.name":"{apiproxy.name}",
                "apiproxy.revision":"{apiproxy.revision}",
                "proxy.pathsuffix":"{proxy.pathsuffix}",
                "apigee.apiproduct.name":"{apigee.apiproduct.name}",
                "apigee.client_id":"{apigee.client_id}",
                "apigee.developer.app.name":"{apigee.developer.app.name}",
                "request.header.X-Forwarded-For":"{request.header.X-Forwarded-For}",
                "request.verb":"{request.verb}",
                "log.uuid":"{messageid}",
                "client.received.start.timestamp":"{client.received.start.timestamp}",
                "client.sent.end.timestamp":"{client.sent.end.timestamp}",
                "target.sent.start.timestamp":"{target.sent.start.timestamp}",
                "target.received.end.timestamp":"{target.received.end.timestamp}",
                "request.uri":"{request.uri}",
                "request.querystring":"{request.querystring}",
                "target.url":"{target.url}",
                "target.request.url":"{request.url}",
                "target.received.content.length":"{target.received.content.length}",
                "message.status.code":"{message.status.code}",
                "response.status.code":"{response.status.code}",
                "request.header.Accept":"{request.header.Accept}",
                "proxy.basepath":"{proxy.basepath}",
                "response_reason_phrase":"{message.reason.phrase}",
                "organization.name":"{organization.name}",
                "virtualhost.name":"{virtualhost.name}",
                "request.header.host":"{request.header.host}",
                "error.state":"{error.state}" 
            }
        
        </Message>
        <FileName>test2.log</FileName>
        <FileRotationOptions rotateLogFileOnStartup="false">
            <FileRotationType>TIME_SIZE</FileRotationType>
            <MaxFileSizeInMB>512</MaxFileSizeInMB>
            <MaxFilesToRetain>1</MaxFilesToRetain>
            <RotationFrequency unit="day">1</RotationFrequency>
        </FileRotationOptions>
    </File>
    <BufferMessage>true</BufferMessage>
    <logLevel>ERROR</logLevel>
</MessageLogging>
Solved Solved
0 3 2,307
1 ACCEPTED SOLUTION

This, sort of works:

"date/time":"{system.time.year}-{system.time.month}-{system.time.day} {system.time.hour}:{system.time.minute}:{system.time.second}" 

But for some reason the time ends up looking like this:

 "date/time":"2018-7-24 8:0:54",

View solution in original post

3 REPLIES 3

This, sort of works:

"date/time":"{system.time.year}-{system.time.month}-{system.time.day} {system.time.hour}:{system.time.minute}:{system.time.second}" 

But for some reason the time ends up looking like this:

 "date/time":"2018-7-24 8:0:54",

Unfortunately I don't know of an easy, 1-line change you can make that would allow you to format the date in your message in the exact way you'd like to.

Will this make you feel better? There's a forthcoming feature that would allow you to do this:

<Message>
    {
        "system.timestamp":"{timeFormatUTCMs(formatString,system.timestamp)}",

...where formatString is

yyyyMMdd-HHmmss

In fact I thought this feature would be available for you by now, and the documentation has been released. I even have a repo with an example API Proxy that demonstrates what you can do. For example, look here.

The key is the "message template", which is used in various places in Apigee Edge policy configuration. Not just in the AssignVariable element of AssignMessage, but also in the Message element for MessageLogging policy, and in lots of other places.

I sure hope that we'll be able to release this feature for all of you to use, very very soon.

But FOR NOW, you have to resort to an extra Javascript step that formats your timestamp in the way you prefer. You might rely on a date formatter library like this.

Thanks for ref to the workaround. I think for now I will just go with what I got working... faced some other issues with getting the policy to trigger in one of my projects so will try to find out why..

https://community.apigee.com/questions/59347/messagelogging-not-working.html?childToView=59354#comme...