開発者ドキュメント

GAE:ログメッセージをファイルに出力する方法

デフォルトでは、すべてのログメッセージがログコンソールに出力されます。ロギングの設定を変更するには、

\ {Google App Engine SDKディレクトリ} \ google \ appengine \ tools \ `dev

appserver

main.py`

ファイルを探します。


File:dev

appserver

main.py

– パターンを見つける

#...
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')
#...

ファイルへの出力

ログメッセージをファイルに出力するために、以下のように `dev

appserver

main.py`でログインの設定を変更することができます:

#...
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')
#...


dev

appserver

main.py`を変更した後、

dev__appserver.py`を再起動してください。

ログコンソールにログメッセージは表示されず、ファイルに出力されます(この例では、すべてのログメッセージは ”

/Users/lokjack/gae.log

“に出力されます)。

ソースコードをダウンロードする

ダウンロードする – リンク://wp-content/uploads/2012/08/gae-logging-to-file.zip[gae-logging-to-file.zip](11 kb)

参考文献

Google App Engineでサーバー上にファイルやフォルダを作成できますか?]

モバイルバージョンを終了