How do you insert a newline in message body of mule logger component
Asked Answered
E

8

10

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.

Eduino answered 6/3, 2013 at 17:44 Comment(0)
P
19

Use MEL:

    <logger
        message="#['Payload is:'+payload+'\nInbound Headers: '+message.inboundProperties.entrySet()+'\nOutbound Headers: '+message.outboundProperties.entrySet()+'\nExceptions: '+exception]"
        level="INFO" />
Proline answered 6/3, 2013 at 18:20 Comment(2)
It would still be better to use System.getProperty('line.separator') instead of \n to make it closs-platform.Forficate
@Forficate Sounds good, but first we would need to make sure that \n isn't already interpreted by MVEL as System.getProperty('line.separator').Proline
F
6

You could do something like this:

Payload is: #[payload] #[System.getProperty('line.separator')] Inbound Headers: ...
Forficate answered 6/3, 2013 at 18:19 Comment(0)
A
2

use expression-transformer:

<expression-transformer expression="#[message.payload = message.payload + System.getProperty('line.separator')]" doc:name="Append CRLF"/>
Autogiro answered 4/6, 2013 at 17:31 Comment(0)
K
2

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']

Kinch answered 14/9, 2016 at 4:14 Comment(0)
F
1

we can you the below format

#['\n'] #['\n']  #['\n'] #['\n']  #[payload] #[System.getProperty('line.separator')]
Froufrou answered 4/9, 2018 at 9:55 Comment(1)
#['\n'] is best and simplest option of all - thank you!Heffron
R
0

//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"/>
Ratepayer answered 19/12, 2018 at 1:7 Comment(0)
N
0

You can use this syntax with Mule 4:

My Input payload: #["\n"] #[payload]

Nicholson answered 3/6, 2022 at 9:47 Comment(0)
T
-1

Try this in literal mode. #["\n"] #[ payload]

Theodosia answered 12/8, 2021 at 7:50 Comment(1)
Isn't it the same as in Lova's answer?Duclos

© 2022 - 2024 — McMap. All rights reserved.