I'm trying to output a pattern that contains the characters < > in the form
08:06:41 DEBUG 69 [ch.fhnw.edu.rental.model.Movie] - <Movie 'Cars' created>
Where <Movie 'Cars' created> is the log-message.
My PatternLayout is as follows:
<PatternLayout pattern="%d{HH:mm:ss} %-5p %L [%c] - <%m%n>"/>
Unfortunately this produces the error
[Fatal Error] log4j2.xml:5:65: The value of attribute "pattern" associated with an element type "PatternLayout" must not contain the '<' character.
How can I escape the < > characters without hardcoding them into the source code?
You can use HTML entity codes for this: < for < and > for >.
Be careful where you place them:
<PatternLayout pattern="%d{HH:mm:ss} %-5p %L [%c] - <%m>%n"/>
In the above example, the > needs to be placed before the %n since %n generates a newline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With