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.

user1760178
  • 6,277
  • 5
  • 27
  • 57
Gary Sharpe
  • 2,369
  • 8
  • 30
  • 51

8 Answers8

19

Use MEL:

    <logger
        message="#['Payload is:'+payload+'\nInbound Headers: '+message.inboundProperties.entrySet()+'\nOutbound Headers: '+message.outboundProperties.entrySet()+'\nExceptions: '+exception]"
        level="INFO" />
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • 2
    It would still be better to use System.getProperty('line.separator') instead of \n to make it closs-platform. – Seba Mar 06 '13 at 19:21
  • 1
    @Seba Sounds good, but first we would need to make sure that `\n` isn't already interpreted by MVEL as `System.getProperty('line.separator')`. – David Dossot Mar 06 '13 at 19:25
6

You could do something like this:

Payload is: #[payload] #[System.getProperty('line.separator')] Inbound Headers: ...
Seba
  • 2,319
  • 15
  • 14
2

use expression-transformer:

<expression-transformer expression="#[message.payload = message.payload + System.getProperty('line.separator')]" doc:name="Append CRLF"/>
Jonathan
  • 43
  • 2
  • 6
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']

1

we can you the below format

#['\n'] #['\n']  #['\n'] #['\n']  #[payload] #[System.getProperty('line.separator')]
Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
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"/>
Sharif
  • 1,488
  • 17
  • 21
0

You can use this syntax with Mule 4:

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

-1

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