GAE : how to output log messages to a file
By default, all logging messages will output to log console. To change the logging settings, find this file – {Google App Engine SDK directory}\google\appengine\tools\dev_appserver_main.py
.
File : dev_appserver_main.py – Find following pattern
#...
import getopt
import logging
import os
import signal
import sys
import tempfile
import traceback
logging.basicConfig(
level=logging.INFO,
format='%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s')
#...
Output to File
In order to output log messages to a file, we can change the configuration of logging in dev_appserver_main.py
like in below:
#...
import getopt
import logging
import os
import signal
import sys
import tempfile
import traceback
# default , comment out
#logging.basicConfig(
# level=logging.INFO,
# format='%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s')
# new log settings , output to a file
logging.basicConfig(
filename='/Users/lokjack/gae.log',
filemode='a',
level=logging.DEBUG,
format='%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s')
#...
Restart the dev_appserver.py
after changed the dev_appserver_main.py
.
Now, the log console would not show any log messages, instead all output to a file (In this example, all log messages will be output to “/Users/lokjack/gae.log“).
Note
This hacks only works on local GAE development environment.
This hacks only works on local GAE development environment.
Download Source Code
Download it – gae-logging-to-file.zip (11 kb)
References
About Author
Comments
Subscribe
0 Comments