如何配置 Tomcat 通过 syslog 记录所有内容?

发布于 2024-09-11 17:42:39 字数 575 浏览 10 评论 0原文

我正在尝试配置 Tomcat 和 web 应用程序(Atlassian JIRA)以通过 syslog 记录所有内容。

以下是我添加到 web 应用程序 log4j.properties (atlassian-jira/WEB-INF/classes/log4j.properties) 中的内容:

log4j.rootLogger=WARN, syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.facility=LOCAL0
log4j.appender.syslog.layout.ConversionPattern=%-5p [%t] [%c]: %m%n
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.SyslogHost=my.syslog.server.fqdn

但是,没有通过 syslog 发送任何内容。我嗅探了端口 514 上的传出数据包,但没有出现任何内容。

感谢您的帮助!

I'm trying to configure Tomcat and a webapp (Atlassian JIRA) to log everything over syslog.

Here is what I added to the webapp log4j.properties (atlassian-jira/WEB-INF/classes/log4j.properties) :

log4j.rootLogger=WARN, syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.facility=LOCAL0
log4j.appender.syslog.layout.ConversionPattern=%-5p [%t] [%c]: %m%n
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.SyslogHost=my.syslog.server.fqdn

However, nothing is sent over syslog. I sniffed outgoing packets on the port 514 and nothing appears.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请爱~陌生人 2024-09-18 17:42:39

这是我当前使用的解决方案:

  1. 我删除了conf/logging.properties文件
  2. 我修改了atlassian-jira/WEB-INF/classes/log4j.properties以禁用所有文件日志记录操作,留下仅控制台日志记录
  3. 我修改了 catalina.sh 以便将其输出通过管道传输到 logger

我想此解决方案不符合 java-world 标准。但它正在发挥作用。

但是,我仍在寻找一种更清晰的方式来记录系统日志。

Here is the solution I currently use :

  1. I removed the conf/logging.properties file
  2. I modified the atlassian-jira/WEB-INF/classes/log4j.properties in order to disable all file logging operations, leaving only console logging
  3. I modified catalina.sh in order to pipe its output to logger

I imagine this solution isn't java-world-compliant. But it's working.

However, I'm still looking for a cleaner way to log to syslog.

素罗衫 2024-09-18 17:42:39

我还非常想要 JIRA 的系统日志附加程序,它不需要单独的记录器进程。

修改了/opt/jira/atlassian-jira/WEB-INF/classes/log4j.properties,如Q中所示,相关结果如下:

...
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
log4j:ERROR Could not instantiate class [org.apache.log4j.net.SyslogAppender].
java.lang.ClassNotFoundException: org.apache.log4j.net.SyslogAppender
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179)
        at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320)
        at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664)
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
        at org.apache.log4j.Logger.getLogger(Logger.java:118)
        at com.atlassian.jira.startup.LauncherContextListener.<clinit>(LauncherContextListener.java:40)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4149)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
log4j:ERROR Could not instantiate appender named "syslog".
...

我可能是错的,但它看起来像org.apache.log4j.helpers .Loader.loadClass 类加载器知道 org.apache.log4j 包,但 不知道 org.apache.log4j.net 包,即使它们驻留在同一个包中jar /opt/jira/lib/log4j-1.2.15.jar

在撰写本文时:JIRA 4.4.1 通过 Linux 64 位安装程序。

I also would really like a syslog appender for JIRA that doesn't require a separate logger process.

Modified /opt/jira/atlassian-jira/WEB-INF/classes/log4j.properties as indicated in the Q with relevant result as follows:

...
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23-Sep-2011 12:12:44 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
log4j:ERROR Could not instantiate class [org.apache.log4j.net.SyslogAppender].
java.lang.ClassNotFoundException: org.apache.log4j.net.SyslogAppender
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.apache.log4j.helpers.Loader.loadClass(Loader.java:179)
        at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:320)
        at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:121)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:664)
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
        at org.apache.log4j.Logger.getLogger(Logger.java:118)
        at com.atlassian.jira.startup.LauncherContextListener.<clinit>(LauncherContextListener.java:40)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4149)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
log4j:ERROR Could not instantiate appender named "syslog".
...

I could be wrong, but it looks like the org.apache.log4j.helpers.Loader.loadClass class loader knows about the org.apache.log4j package but NOT org.apache.log4j.net package even though they reside in the same jar /opt/jira/lib/log4j-1.2.15.jar.

At time of writing: JIRA 4.4.1 via Linux 64-bit Installer.

情绪 2024-09-18 17:42:39

对于访问日志:https://github.com/magwas/SyslogValve
由于使用的 api 不断变化,因此可能需要针对您的 tomcat 版本进行调整。

For access logs: https://github.com/magwas/SyslogValve
It might needs tweaking for your tomcat version through, as the used api is constantly changing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文