4
votes

Google App Engine uses java.util.logging.Logger (JUL) for all logging. Thus to log anything (and then subsequently retrieve it via the LogService), you just log like you normally do with 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 even provides a CapabilitiesService that you can check before calling any service method to see if that service is currently enabled or not.

So I ask: is there ever a chance that JUL logging operation will ever fail:

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

If not, why? And if so, what can I do to "failover" in the case that JUL has choked? Thanks in advance.

3
In the bounty text, I meant logger.info(), not logger.finfo(). Finfo is just ridiculous. - IAmYourFaja

3 Answers

2
votes
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 )
  • Send an email ( can fail for many socket I/O related reasons )
  • Write to DB ( can fail for many DB related reasons )
1
votes

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.


Also, because this gave me a smile during several weeks of crashing hell: 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. The exception to this rule is logging. When Logging fails to record the downtime, Uptime goes up. 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.

1
votes

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(...).

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. If you can't, then the logger.info(...) failed, and you can have your app react however you like.

I always expose a secure servlet on my GAE apps that pings the Capabilities Service and asks for a status check on each service. 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. You can tie this "log checking" cron job into that kind of a service check.