How do you insert a newline in message body of mul

2019-04-06 10:44发布

Can anyone tell me how to insert a new line in the message of a mule logger component?

For example, I have the following in the message for the logger:

Payload is: #[payload] 
Inbound Headers:  #[headers:INBOUND:*] 
Outbound Headers:  #[headers:OUTBOUND:*]  
Exceptions:  #[exception]

I'd like to insert a new line after each of the above. I've tried just adding \n to the end of each line, but that didn't work.

6条回答
太酷不给撩
2楼-- · 2019-04-06 11:04

There are a couple of ways to do this:

1) Use: #[System.getProperty('line.separator')]

2) Use: #['\n'] eg: #['Hello\n'+payload+'Welcome to \n new line']

查看更多
贼婆χ
3楼-- · 2019-04-06 11:12

Use MEL:

    <logger
        message="#['Payload is:'+payload+'\nInbound Headers: '+message.inboundProperties.entrySet()+'\nOutbound Headers: '+message.outboundProperties.entrySet()+'\nExceptions: '+exception]"
        level="INFO" />
查看更多
闹够了就滚
4楼-- · 2019-04-06 11:16

we can you the below format

#['\n'] #['\n']  #['\n'] #['\n']  #[payload] #[System.getProperty('line.separator')]
查看更多
▲ chillily
5楼-- · 2019-04-06 11:17

//This should work. tested in mule 3.9 CE

<logger message="Payload is #[message.payloadAs(java.lang.String)]  #[System.lineSeparator()]  INBOUND HEADERS =  #[headers:inbound:*]" level="INFO" doc:name="Logger"/>
查看更多
我想做一个坏孩纸
6楼-- · 2019-04-06 11:19

use expression-transformer:

<expression-transformer expression="#[message.payload = message.payload + System.getProperty('line.separator')]" doc:name="Append CRLF"/>
查看更多
小情绪 Triste *
7楼-- · 2019-04-06 11:22

You could do something like this:

Payload is: #[payload] #[System.getProperty('line.separator')] Inbound Headers: ...
查看更多
登录 后发表回答