使用 log4j 记录到某个文件(HQ 的问题)
编辑:所以看来问题出在我的日志处理程序/附加程序和根记录器的日志级别中。不知何故,总部(只是另一个应用程序)将其日志配置为获取所有日志消息。我需要的是禁止我的 jsa 处理程序向上传递日志消息。
你好。我的日志记录有问题。
信息:我在服务器上运行了多个应用程序(包括 hyperic、进一步的 HQ)。服务器上还有一个正在运行的常规应用程序/脚本。 HQ 触发一个脚本,但实际上没有与它集成,这意味着 HQ 对 groovy 脚本的所有了解都是由 groovy 脚本生成的命令行输出。
问题:总部日志以某种方式从 groovy 脚本获取所有消息。我可能会假设,当 groovy 进行日志记录时,它还会将所有日志打印到标准 java 日志,而标准 java 日志又被 HQ 覆盖。
我有一个 groovy 脚本的 log4j 配置,这应该使得日志记录到默认的 java 日志成为不可能。
log4j.rootLogger=info, jsa
log4j.logger.net.schmizz.sshj=WARN
#Defining logger scope and it's params
log4j.logger.mypackage=INFO, jsa
log4j.appender.jsa=org.apache.log4j.RollingFileAppender
log4j.appender.jsa.File=logs/jsa.log
log4j.appender.jsa.MaxFileSize=1MB
log4j.appender.jsa.MaxBackupIndex=5
log4j.appender.jsa.layout=org.apache.log4j.PatternLayout
log4j.appender.jsa.layout.ConversionPattern=%d [%t] %-5p %c (%F:%L) - %m%n
尽管我仍然收到所有令人讨厌的日志记录。
PS:我也使用 slf4j 来提高灵活性,尽管我怀疑它是否已经做到了这一点。
EDIT: So it appears that the problem is in the log level of my log handlers/appenders and root logger. Somehow HQ (simply the other app) has it's logs configured to get all log messages. What I need is to prohibit my jsa handler to pass log messages up the level.
Hi. I have an issue with my logging.
Info: I've got several apps (including hyperic, further HQ) running on a server. And there's also a groovy app/script running on the server. HQ triggers a script but actually has no integration with it, meaning that all HQ knows about groovy script is the output in command line produced by groovy script.
Problem: somehow HQ logs get all the messages from groovy script. I may assume that when groovy does it's logging it also prints all the logs to standard java log which is in turn overridden by HQ.
I have a log4j configuration for groovy script which should have made logging to default java log impossible.
log4j.rootLogger=info, jsa
log4j.logger.net.schmizz.sshj=WARN
#Defining logger scope and it's params
log4j.logger.mypackage=INFO, jsa
log4j.appender.jsa=org.apache.log4j.RollingFileAppender
log4j.appender.jsa.File=logs/jsa.log
log4j.appender.jsa.MaxFileSize=1MB
log4j.appender.jsa.MaxBackupIndex=5
log4j.appender.jsa.layout=org.apache.log4j.PatternLayout
log4j.appender.jsa.layout.ConversionPattern=%d [%t] %-5p %c (%F:%L) - %m%n
Though I still get all the nasty logging.
P.S.: I also use slf4j for flexibility, though I doubt it cold have done this trick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于日志记录(尽管可加性选项在这里很有用),而在于 groovy 文件所在的目录。在 HQ 版本 4.3 中,hq-plugins 中的所有文件都保存到 tmp 目录中,更改的文件也保存在那里(所以如果你有一个文件 foo.txt 并将其放在那里,它将保存在 tmp 中;如果你以某种方式修改它,它也会再次保存在tmp中)。
解决方案:只需将日志、groovy 脚本和其他文件从 hq-plugins 删除到其他位置即可。本例中的 tmp 目录为 $HQ_HOME/server/hq-engine/hq-server/default/tmp/deploy/
The problem is not in logging (though additivity options will be useful here) but in the directory where the groovy files reside. In HQ version 4.3 all the files in hq-plugins are saved to tmp directory and the changed files are also saved there (so if you have a file foo.txt and you put it there, it will be saved in tmp; if you somehow modify it, it will also be saved in tmp, again).
Solution: simply remove logs, groovy scripts and other files from hq-plugins to other location. Tmp directory in this case is
$HQ_HOME/server/hq-engine/hq-server/default/tmp/deploy/