Reputation: 339
I'm trying to integrate Sentry in my Maven project that already uses log4j2.properties as log4j2 configuration file.
The official documentation has just log4j2.xml as configuration example.
What is the way to configure the same example with log4j2.properties?
Upvotes: 4
Views: 1927
Reputation: 781
In my case with log4j 2.17, I needed to add packages = io.sentry.log4j2
to my log4j2.properties
file.
Full file:
status = error
dest = err
name = MyName
packages = io.sentry.log4j2
monitorInterval = 5
appender.console.type = Console
appender.console.name = LogToConsole
appender.console.layout.type = JsonLayout
appender.console.layout.compact = true
appender.console.layout.eventEol = true
appender.console.layout.properties = true
appender.sentry.name = Sentry
appender.sentry.type = Sentry
appender.sentry.dsn = https://[email protected]
rootLogger.level = ${env:LOG_LEVEL:-debug}
rootLogger.appenderRef.console.ref = LogToConsole
rootLogger.appenderRef.sentry.ref = Sentry
Upvotes: 2
Reputation: 11
This solution for integrating sentry with log4j2.properties worked for me perfectly along with stdout logging.
log4j.rootLogger=INFO, stdout, sentry
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %m%n
log4j.appender.sentry=io.sentry.log4j.SentryAppender
log4j.appender.sentry.Threshold=error
For this, I had to add log4j 1.x version of sentry to my pom.xml
Upvotes: 1
Reputation: 427
I've the same problem.
Here is my log4j2.properties
appenders = console,Sentry
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = ${env:log4j.csl.pattern:-info}
appender.Sentry=io.sentry.log4j.SentryAppender
appender.Sentry.name=Sentry
appender.Sentry.type=Sentry
rootLogger.level = ${env:log4j.root.loglevel:-info}
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
loggers=csl,sentry
logger.csl.name = io.sirnino
logger.csl.level = ${env:log4j.csl.loglevel:-debug}
logger.csl.additivity = false
logger.csl.appenderRefs = stdout
logger.csl.appenderRef.stdout.ref = STDOUT
logger.sentry.name = sentry
logger.sentry.level = WARN
logger.sentry.appenderRefs = Sentry
The app starts properly but, in a nutshell, seems to ignore the Sentry logger. Any idea?
Upvotes: 2
Reputation: 6408
It should work also with log4j2.properties
. Have you tried and it failed?
Maybe the docs should explicitly state that it's supported.
If it doesn't work, you can raise an issue on GitHub:
https://github.com/getsentry/sentry-java/issues
Upvotes: 0