Google App Engine - 配置默认记录器以发送电子邮件
在我的 GAE/J 应用程序中,如何配置默认记录器以通过电子邮件报告错误?
In my GAE/J application, how would I configure the default logger to report errors via email?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SMTPHandler 已存在,但由于不满足依赖性而无法与 GAE/J 一起使用。看一下SMTPHandler的源代码并将其适配到GAE/J。
An SMTPHandler already exists, but cannot be used with GAE/J because of unsatisfied dependencies. Take a look at the source code of SMTPHandler and adapt it to GAE/J.
包含的 MailHandler JavaMail 1.5.3 及更高版本 已内置 支持 Google App Engine。确保您使用的是最新版本的 JavaMail。
对于 GAE/J,您可以下载 logging-mailhandler.jar 并将其包含在您的项目中。
否则,可以使用 java.net Maven 存储库 或 Maven Central 并通过 groupid=com.sun.mail 和 artifactId=logging-mailhandler 拉取依赖项。
设置依赖项后,配置您的logging.properties 以包含正确的日志设置和电子邮件包络。以下是一个logging.properties 文件示例:
接下来创建代码来安装MailHandler 因为 LogManager 将无法看到logging-mailhandler.jar 。
以下是 ServletContextListener 的示例,它将在根记录器上安装 MailHandler。
The MailHandler included with JavaMail 1.5.3 and later have built in support for Google App Engine. Make sure you are using the most current version of JavaMail.
For GAE/J you can download the logging-mailhandler.jar and include it in your project.
Otherwise, can use the java.net Maven repository or Maven Central and pull the dependency by groupid=com.sun.mail and artifactId=logging-mailhandler.
After the dependency is setup, then configure your logging.properties to contain the correct log settings and email envlope. Here is a sample logging.properties file:
Next create code to install the MailHandler because the LogManager won't be able to see the logging-mailhandler.jar.
Here is an example of a ServletContextListener that will install the MailHandler on the root logger.