嵌入式码头和复杂测井 [英] Embedded Jetty and Complex Logging

查看:95
本文介绍了嵌入式码头和复杂测井的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jetty 9用于嵌入式服务器,并且一切正常.剩下的一件事就是日志问题.

Jetty 9 is used for the embedded server and everything works well. One thing that remains is the logging issue.

在该mvn:jetty-run之前,他带有自己的日志记录设置,并记录到控制台.那对发展是有好处的.在生产环境中,我们需要更特殊的东西.

Prior to that mvn:jetty-run brings his own logging setup with it and logs to the console. That is good for development. In the production environment we need something more special.

当前,SLF4J在启动时抱怨没有可用的绑定,因此我们可以自由选择.

Currently on start-up the SLF4J complains about, that there is no binding available, so we can chose freely.

这就是我们要存档的内容:

That is what we want to archive:

  1. 如果要在非生产环境中启动,我们需要登录到控制台.
  2. 在生产环境中,应在单个日志文件中进行日志记录,但每天轮换使用以下命名模式:logs/logname-date.log(例如,logs/application-20130926.log)

我们使用命令行参数"-production"来区分生产模式和非生产模式.

We distinguish between the production and non-production mode using a command line argument '-production'.

由于码头服务器是嵌入式的,所以我希望有一个解决方案,我们可以完全配置记录器,而无需管理xml或properties-files,从而无需进行日志记录配置方面的工作.

Since the jetty server is embedded I would love to have a solution which we can fully configure the logger without the need to manage xml or properties-files taking the logging configuration aspect out of the deployment process.

那么我们有什么选择,以及如何以最好的方式做到这一点?

So what options do we have and how can we do this in the best possible way?

更新:似乎需要进行注销.它支持日志文件旋转,还可以使用控制台输出.剩下的难题是如何以编程方式在没有其他文件的情况下执行此操作.

Update: It seems that logback is the way to go. It has support for the logfile rotation and also makes it possible to use a console output. The difficult question remaining is how to do this programatically and without additional files.

推荐答案

所以最后是完整的图片.

So finally here is the complete picture.

下面仅以编程方式描述了所有日志记录配置: http://logback.qos.ch/manual/configuration.html#joranDirectly

After all the logging configuration in a programmatic way is just described here: http://logback.qos.ch/manual/configuration.html#joranDirectly

我使用Joakim所说的logback API.一旦学习了如何使用JoranConfigurator对象进行编程,一切都将变得非常简单.玩它,您会得到图片.

I use the logback API just as stated by Joakim. Once you learn how to program it programmatically using the JoranConfigurator object everything is quite easy. Play with it and you get the picture.

我设法完成了手头的所有任务.

I managed to accomplished all tasks at hand.

感谢Joakim的帮助.我很想念JoranConfigurator.谢谢!

Thanks for the help Joakim. I was missing the JoranConfigurator thingy. Thanks!

更新:

我使用了StringReader并将xml配置文件直接嵌入到Logging配置类中.这样,我不必管理其他文件,日志记录也可以按预期进行.

I used a StringReader and embedded the xml configuration file directly in the Logging configuration class. This way I dont have to manage additional files and logging works as expected.

这篇关于嵌入式码头和复杂测井的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆