Skip to content

Commit 84826de

Browse files
committed
Add log4j2 config and note about ex-info data maps
1 parent 91dc6f9 commit 84826de

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ The above approach is problematic given that applications often inadvertently pu
9090
in multiple logging implementations as transitive dependencies. As such, it is
9191
_strongly_ advised that you set the system property.
9292

93+
### Log4J2
94+
95+
A simple Log4j2 [configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html):
96+
97+
```properties
98+
status = warn
99+
monitorInterval = 5
100+
101+
appender.console.type = Console
102+
appender.console.name = STDOUT
103+
appender.console.layout.type = PatternLayout
104+
appender.console.layout.pattern = %date %level %logger %message%n%throwable
105+
106+
rootLogger.level = info
107+
rootLogger.appenderRef.stdout.ref = STDOUT
108+
```
109+
110+
*Note:* The above [pattern](https://logging.apache.org/log4j/2.x/manual/layouts.html#Patterns)
111+
explicitly uses `%throwable` so that `clojure.lang.ExceptionInfo` exceptions
112+
will be printed with their data maps. If either `%xThrowable` (the default) or
113+
`%rThrowable` is used, the data maps will not be printed.
114+
115+
## FAQ
116+
117+
#### When logging an `ex-info` exception, why isn't the data map printed?
118+
119+
This is likely because the logging implementation is printing the contents of
120+
`Throwable.getMessage()`, which returns just the message arg to `ex-info`.
121+
122+
Logging implementations that print the contents of `toString()` or use `Throwable.printStackTrace(...)`
123+
will end up printing the data map.
93124

94125
## Thanks
95126

0 commit comments

Comments
 (0)