简体   繁体   English

java.util.logging.Logger方法可以在Google App Engine上失败吗?

[英]Can java.util.logging.Logger methods ever fail on Google App Engine?

Google App Engine uses java.util.logging.Logger (JUL) for all logging. Google App Engine使用java.util.logging.Logger (JUL)进行所有日志记录。 Thus to log anything (and then subsequently retrieve it via the LogService ), you just log like you normally do with JUL: 因此,要记录任何内容(然后通过LogService检索它),您只需LogService使用JUL进行记录:

private Logger logger = Logger.getLogger(this.class.getName());

// ...

public void doWhatever() {
    logger.info("This will be logged.");
}

But if you read over the GAE tutorials/guides for their various service APIs (Memcache, Mail, Datastore, etc.), they all reiterate that you should always code for the possibility that one of their services are down. 但是,如果您阅读GAE教程/指南中的各种服务API(Memcache,Mail,Datastore等),他们都会重申您应该始终对其服务中断的可能性进行编码。 GAE even provides a CapabilitiesService that you can check before calling any service method to see if that service is currently enabled or not. GAE甚至提供了一个CapabilitiesService ,您可以在调用任何服务方法之前检查它以查看当前是否启用该服务。

So I ask: is there ever a chance that JUL logging operation will ever fail: 所以我问:JUL日志操作是否有可能失败:

logger.info("Can I ever fail and not get logged?"); logger.info(“我可能会失败并且不会被记录吗?”);

If not, why? 如果没有,为什么? And if so, what can I do to "failover" in the case that JUL has choked? 如果是这样,在JU​​L窒息的情况下,我可以做些什么来“故障转移”? Thanks in advance. 提前致谢。

logger.info("Can I ever fail and not get logged?");

Of course it can fail. 当然它可能会失败。

Configuration behind this innocently looking line may: 这条无辜的线条背后的配置可能是:

  • Write a message to console ( console writes can be not initialized yet, or already shutdown ) 向控制台写入消息(控制台写入尚未初始化,或已经关闭)
  • Append a message to file ( can fail for many file I/O related reasons ) 将消息附加到文件(可能因许多文件I / O相关原因而失败)
  • Send an email ( can fail for many socket I/O related reasons ) 发送电子邮件(可能因许多套接字I / O相关原因而失败)
  • Write to DB ( can fail for many DB related reasons ) 写入DB(由于许多与DB相关的原因可能会失败)

One option, if you're consistently crashing and trying to figure something out, is to send async HTTP calls (as a log mechanism) to another server. 如果您一直崩溃并试图解决问题,一种选择是将异步HTTP调用(作为日志机制)发送到另一台服务器。


Also, because this gave me a smile during several weeks of crashing hell: https://groups.google.com/d/msg/google-appengine/js5CeRWLQZ0/KrW2CpJ4JuYJ 此外,因为这让我在几周的地狱崩溃中笑了起来: https//groups.google.com/d/msg/google-appengine/js5CeRWLQZ0/KrW2CpJ4JuYJ

In most systems the Uptime is 100% minus the summation of the downtime of all other systems. 在大多数系统中,正常运行时间是100%减去所有其他系统停机时间的总和。 The exception to this rule is logging. 此规则的例外是日志记录。 When Logging fails to record the downtime, Uptime goes up. 当Logging无法记录停机时间时,Uptime会上升。 As a result Google has been working hard to build a logging system that goes down just ahead of all other systems, and comes up shortly after. 因此,谷歌一直在努力建立一个比所有其他系统领先的日志系统,并在不久之后出现。

I've ran into this same problem, and yes the logging service can fail without errors. 我遇到了同样的问题, 的,日志服务可能会失败而没有错误。 The best you're going to get (until GAE improves the logging service API), is to cron a job to wake up, say, every minute, and perform a logger.info(...) . 你将获得的最好logger.info(...)直到GAE改进了日志服务API),就是每分钟唤醒一个工作,然后执行logger.info(...)

Then run a LoggingService#fetchLogs(...) , filtered to only retrieve the AppLogLine containing the most recent logger call, and check to make sure you can retrieve it. 然后运行LoggingService#fetchLogs(...) ,过滤以仅检索包含最新记录器调用的AppLogLine ,并检查以确保您可以检索它。 If you can't, then the logger.info(...) failed, and you can have your app react however you like. 如果你不能,那么logger.info(...)失败了,你可以让你的应用程序做出反应。

I always expose a secure servlet on my GAE apps that pings the Capabilities Service and asks for a status check on each service. 我总是在我的GAE应用程序上公开一个安全的servlet来ping功能服务,并要求对每个服务进行状态检查。 If the service is disabled or down for maintenance, I have an external monitor (that checks this URL every 5 mins) send me a text message. 如果服务被禁用或关闭以进行维护,我有一个外部监视器(每5分钟检查一次这个URL)给我发短信。 You can tie this "log checking" cron job into that kind of a service check. 您可以将此“日志检查”cron作业绑定到该类服务检查中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM