如何将自定义日志处理程序添加到Google App Engine? [英] How to add custom log handler to Google App Engine?

查看:81
本文介绍了如何将自定义日志处理程序添加到Google App Engine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的Java应用程序添加自定义日志处理程序.我实现了一个InnerLogger类,该类扩展了java.util.Logging.Handler类.并在我的logging.properties中声明为处理程序:

I am trying to add a custom log handler to my java application. I have implemented a InnerLogger class that extends java.util.Logging.Handler class. And in my logging.properties declared as a handler:

handlers:com.mycompany.util.InnerLogger

但是当我启动开发服务器时,出现以下错误:

But when I launch the development sever, I got the following error:

Can't load log handler "com.mycompany.util.InnerLogger"
java.lang.ClassNotFoundException: com.mycompany.util.InnerLogger

我可以将自定义处理程序一个一个地添加到记录器中,但是我只是想知道是否有一种方法可以将其添加到所有记录器中.

I can add my custom handler to loggers one by one ,but I just wondering is there a way to add it to all loggers.

谢谢

推荐答案

在我的应用程序初始化时,我能够将Handler添加到根Logger中.您可以将此代码放入预热任务或Servlet过滤器中.

I was able to add a Handler to the root Logger when my application initializes. You can put this code in a warmup task or servlet filter.

private static Logger LOG;

...

LOG = Logger.getLogger("");
LOG.addHandler(myCustomHandler);

它不像使用logging.properties那样优雅,但是在GAE上运行时,这是一个适当的解决方法.

Its not as graceful as using logging.properties, but it is an adequate workaround when running on GAE.

这篇关于如何将自定义日志处理程序添加到Google App Engine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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