Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does GoogleAppEngineLauncher keep the local log files?

GoogleAppEngineLauncher can display the local log file of my app while it is running on my Mac during development. However, I can't change the font size there so I would like to use the tail command to watch the log file myself.

It's a shame but I can't find the log files. They are not under /var/log/, ~/Library/Logs or /Library/Logs. Do you know where they are?

(Maybe there are no physical files, just the stdout of the python development environment and so the log is only available in the launcher application.)

like image 388
zengabor Avatar asked May 16 '10 17:05

zengabor


People also ask

Which logs can be accessed from App Engine UI?

Logs in Google Cloud Platform for App Engine, and all other Google Cloud Platform resources can be viewed in Stackdriver Logging.

Where do log files come from?

Log files are automatically computer-generated whenever an event with a specific classification takes place on the network. Log files exist for software and hardware developers to troubleshoot and debug their creations when they access a textual record of the events that the system is producing.

How do you read a log viewer?

Version 1.1.Press Ctrl+F or Command+F to find words or text in the log file.


1 Answers

As you surmise, and can confirm by studying the source file /usr/local/google_appengine/google/appengine/tools/dev_appserver.py, the logs are not being written to disk (a cStringIO.StringIO instance is used to keep them in memory, as the rest of the code is oriented to writing them "to a file-like object").

What I would recommend is writing your own app server script, which imports dev_appserver, subclasses dev_appserver.ApplicationLoggingHandler, and overrides just one method:

from google.appengine.tools import dev_appserver

class MyHandler(dev_appserver.ApplicationLoggingHandler):

    def __init__(self, *a, **k):
        dev_appserver.ApplicationLoggingHandler.__init__(self, *a, **k)
        self.thefile = open('/tmp/mylog.txt', 'w')

    def emit(self, record):
        dev_appserver.ApplicationLoggingHandler(self, record)
        self.thefile.write(str(record) + '\n')
        self.thefile.flush()

You also need to ensure this class is used instead of the standard one, e.g. by subclassing the dispatcher or ensuring you use its dependency-injection capability. (dev_appserver_main.py lets you control this better, I think).

I think this customization approach is far more cumbersome than it should be (it's perfectly normal to want the logs written to file, after all -- either to display them differently, as you desire, or to process them later with some auxiliary script), and so I'd also recommend putting a feature request on app engine's tracker: dev_appserver.py should accept one more flag, which, if specified, gives the path on which to write logs to disk.

And, to be honest, if I needed this feature right now, myself, I'd do it the dirty way: editing that .py file (and its related _main.py) to add said flag and its use. That should be a dozen lines in all, much easier than the "canonical" way I just outlined. Of course, it is dirty because every time there's a new SDK you'll have to apply the patch again, and again, and again... which is why one should also propose the patch on GAE's tracker, as part of the feature request I suggested, hoping it gets accepted soon!-)

like image 176
Alex Martelli Avatar answered Oct 22 '22 04:10

Alex Martelli