英文:
Sentry with log4j2.properties
问题
我正在尝试将Sentry集成到我的Maven项目中,该项目已经在使用log4j2.properties作为log4j2的配置文件。
官方文档1中只提供了使用log4j2.xml的配置示例。
请问如何使用log4j2.properties配置与示例相同的方式?
英文:
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?
答案1
得分: 2
我有同样的问题。
这是我的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
应用程序可以正常启动,但简而言之,似乎忽略了Sentry日志记录器。有任何想法吗?
英文:
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?
答案2
得分: 2
在我的情况下,使用 log4j 2.17 版本,我需要将 packages = io.sentry.log4j2
添加到我的 log4j2.properties
文件中。
完整文件:
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://key@my.domain.com
rootLogger.level = ${env:LOG_LEVEL:-debug}
rootLogger.appenderRef.console.ref = LogToConsole
rootLogger.appenderRef.sentry.ref = Sentry
英文:
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://key@my.domain.com
rootLogger.level = ${env:LOG_LEVEL:-debug}
rootLogger.appenderRef.console.ref = LogToConsole
rootLogger.appenderRef.sentry.ref = Sentry
答案3
得分: 1
以下是翻译好的内容:
这个将Sentry与log4j2.properties集成的解决方案对我非常有效,同时还支持标准输出日志记录。
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
为了实现这一点,我不得不在我的pom.xml中添加log4j 1.x版本的sentry。
英文:
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
答案4
得分: 0
应该也可以与log4j2.properties
一起使用。您尝试过吗?失败了吗?
也许文档应该明确说明它是受支持的。
如果不起作用,您可以在GitHub上提出问题:
https://github.com/getsentry/sentry-java/issues
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论