Reputation: 1852
In Log4j2 appenders it's useful to use the contextPath as the filename, as in:
filename="/logs/${web:contextPath}.log
. This means one log configuration can be reused across multiple webapps.
However If a contextPath is /foo/bar
this creates the file /logs/foo/bar.log
. Is there anyway to replace the /
in the contextPath with _
so the filename is /logs/foo_bar.log
?
For me this is more useful than replicating the context path structure directly into the logs. I 've read up on the StringSubstitution docs and can't see anyway to do it, but if anyone has a solution it would be really helpful!
Upvotes: 2
Views: 283
Reputation: 36754
I don't think there is a way to do this out of the box. But you can easily create a custom lookup that does this.
Start by subclassing WebLookup, and replace '/' characters with underscores in the returned string.
Example of creating a custom Log4j2 lookup: see the manual page, or this question.
Upvotes: 1