如何在GAE 寫入server side log (app engine記錄檔)
常常在開發時覺得後台像是一個黑盒子
前端如果想知道這個變數目前的值是什麼
我大可以用alert(var); 去叫出它的值 一目了然
後台其實也有類似的東西 用法如下:
要用之前要先 import logging
logging.info("trace_code_config %s" % trace_code_config)
便會在GAE的dashboard的 Logs中留下一筆記錄 可以在 I 這個標籤裡看到如下的東西:
訊息有五種等級, 偵錯、資訊、警告、錯誤以及重大
好比要印出error --> logging.error("Cannot Parse Facebook Return Token %s"%content)就會在 E Error 這個tag上面看到印出來的訊息
另外 也有列出當下所有環境的function 用法如下:
except Exception, e:
self.dump_log(e)
在GAE 的dashboard 便會看到這樣的東西:
如此一來後台似乎就沒那麼神秘難解了!
延伸閱讀: http://code.google.com/intl/zh-TW/appengine/articles/logging.html
前端如果想知道這個變數目前的值是什麼
我大可以用alert(var); 去叫出它的值 一目了然
後台其實也有類似的東西 用法如下:
要用之前要先 import logging
logging.info("trace_code_config %s" % trace_code_config)
便會在GAE的dashboard的 Logs中留下一筆記錄 可以在 I 這個標籤裡看到如下的東西:
2011-08-29 21:42:05.115 /api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314679284049200 603ms 163cpu_ms 46api_cpu_ms 0kb Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0
114.36.90.246 - - [29/Aug/2011:21:42:05 -0700] "GET /api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314679284049 HTTP/1.1" 200 448 "http://tagtootest.appspot.com/personal_detail/?trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0" "tagtootest.appspot.com" ms=603 cpu_ms=163 api_cpu_ms=47 cpm_usd=0.004674 instance=00c61b117cccf4f2c00fbf49ec58d3381ba25131
I2011-08-29 21:42:04.840
trace_code_config None --> 這是當初在函式中決定要印出的內容
I2011-08-29 21:42:05.079
Login as FB User: <db.models.User object at 0x52f11b44102e98c8>
訊息有五種等級, 偵錯、資訊、警告、錯誤以及重大
- DDebug (least severe)
- IInfo
- WWarning
- EError
- CCritical (most severe)
另外 也有列出當下所有環境的function 用法如下:
except Exception, e:
self.dump_log(e)
在GAE 的dashboard 便會看到這樣的東西:
2011-08-29 21:37:05.360 /api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314678984574200 311ms 140cpu_ms 46api_cpu_ms 0kb Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0
114.36.90.246 - - [29/Aug/2011:21:37:05 -0700] "GET /api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314678984574 HTTP/1.1" 200 448 "http://tagtootest.appspot.com/personal_detail/?trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0" "tagtootest.appspot.com" ms=311 cpu_ms=140 api_cpu_ms=47 cpm_usd=0.004026 instance=00c61b117c37eeb5e8acec19c51a873c658fb837
I2011-08-29 21:37:05.108
Request Url: http://tagtootest.appspot.com/api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314678984574
I2011-08-29 21:37:05.108
Request Headers: {'Accept-Language': 'zh-tw,en;q=0.7,en-us;q=0.3', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0', 'Accept-Charset': 'UTF-32,utf-8;q=0.7,*;q=0.7', 'Host': 'tagtootest.appspot.com', 'Cookie': 'fbs_117063174975384="access_token=117063174975384%7C2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844%7CPdDxHD0_VahdcPVvkhU5aX2pKKM&base_domain=tagtootest.appspot.com&expires=1314684000&secret=3mYWQczF1nvJxHcefXSU_Q__&session_key=2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844&sig=a9d175cecacd5b75e031e4a34c4403eb&uid=100000703046844"', 'Referer': 'http://tagtootest.appspot.com/personal_detail/?trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0', 'X-Appengine-Country': 'TW'}
I2011-08-29 21:37:05.109
Request Argument: [(u'callback', [u'setStaticFeild']), (u'secret', [u'agd0YWd0b29scgwLEgRVc2VyGI7HAww']), (u'noCacheIE', [u'1314678984574']), (u'trace_code', [u'YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0'])]
I2011-08-29 21:37:05.109
Request Cookies: UnicodeMultiDict([(u'fbs_117063174975384', u'"access_token=117063174975384%7C2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844%7CPdDxHD0_VahdcPVvkhU5aX2pKKM&base_domain=tagtootest.appspot.com&expires=1314684000&secret=3mYWQczF1nvJxHcefXSU_Q__&session_key=2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844&sig=a9d175cecacd5b75e031e4a34c4403eb&uid=100000703046844"')])
I2011-08-29 21:37:05.109
Request Body:
I2011-08-29 21:37:05.153
Debug Stack: ExceptionType: <type 'exceptions.EnvironmentError'> ExceptionValue: Settings already configured. Traceback (most recent call last): File "/base/data/home/apps/tagtootest/1.352906439323474420/libs/handlers.py", line 259, in get settings.configure() File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py", line 64, in configure raise EnvironmentError, 'Settings already configured.' EnvironmentError: Settings already configured. Locals by frame Frame configure in /base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py at line 64 default_settings = <type 'module'>: [<module 'django.conf.global_settings' from '/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/global_settings.py'>] self = <class 'django.conf.LazySettings'>: [<django.conf.LazySettings object at 0xee8a2f0428dd9948>] options = <type 'dict'>: [{}] Frame get in /base/data/home/apps/tagtootest/1.352906439323474420/libs/handlers.py at line 271 appdir = <type 'str'>: ['/base/data/home/apps/tagtootest/1.352906439323474420/libs'] self = <class 'dashboard.ajaxs.GetTraceCodeStatAPI'>: [<dashboard.ajaxs.GetTraceCodeStatAPI object at 0xee8a2f0428db0348>] args = <type 'tuple'>: [()] atts = <type 'dict'>: [{}]
I2011-08-29 21:37:05.153
Request Url: http://tagtootest.appspot.com/api/GetTraceCodeStat/?secret=agd0YWd0b29scgwLEgRVc2VyGI7HAww&trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0&callback=setStaticFeild&noCacheIE=1314678984574
I2011-08-29 21:37:05.153
Request Headers: {'Accept-Language': 'zh-tw,en;q=0.7,en-us;q=0.3', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0', 'Accept-Charset': 'UTF-32,utf-8;q=0.7,*;q=0.7', 'Host': 'tagtootest.appspot.com', 'Cookie': 'fbs_117063174975384="access_token=117063174975384%7C2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844%7CPdDxHD0_VahdcPVvkhU5aX2pKKM&base_domain=tagtootest.appspot.com&expires=1314684000&secret=3mYWQczF1nvJxHcefXSU_Q__&session_key=2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844&sig=a9d175cecacd5b75e031e4a34c4403eb&uid=100000703046844"', 'Referer': 'http://tagtootest.appspot.com/personal_detail/?trace_code=YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0', 'X-Appengine-Country': 'TW'}
I2011-08-29 21:37:05.154
Request Argument: [(u'callback', [u'setStaticFeild']), (u'secret', [u'agd0YWd0b29scgwLEgRVc2VyGI7HAww']), (u'noCacheIE', [u'1314678984574']), (u'trace_code', [u'YWdkMFlXZDBiMjlzY2d3TEVnUlZjMlZ5R0k3SEF3dyN0ZXN0'])]
I2011-08-29 21:37:05.154
Request Cookies: UnicodeMultiDict([(u'fbs_117063174975384', u'"access_token=117063174975384%7C2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844%7CPdDxHD0_VahdcPVvkhU5aX2pKKM&base_domain=tagtootest.appspot.com&expires=1314684000&secret=3mYWQczF1nvJxHcefXSU_Q__&session_key=2.AQCaQazyZgjHG86N.3600.1314684000.1-100000703046844&sig=a9d175cecacd5b75e031e4a34c4403eb&uid=100000703046844"')])
I2011-08-29 21:37:05.154
Request Body:
I2011-08-29 21:37:05.155
Debug Stack: ExceptionType: <type 'exceptions.EnvironmentError'> ExceptionValue: Settings already configured. Traceback (most recent call last): File "/base/data/home/apps/tagtootest/1.352906439323474420/libs/handlers.py", line 259, in get settings.configure() File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py", line 64, in configure raise EnvironmentError, 'Settings already configured.' EnvironmentError: Settings already configured. Locals by frame Frame configure in /base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py at line 64 default_settings = <type 'module'>: [<module 'django.conf.global_settings' from '/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/global_settings.py'>] self = <class 'django.conf.LazySettings'>: [<django.conf.LazySettings object at 0xee8a2f0428dd9948>] options = <type 'dict'>: [{}] Frame get in /base/data/home/apps/tagtootest/1.352906439323474420/libs/handlers.py at line 271 appdir = <type 'str'>: ['/base/data/home/apps/tagtootest/1.352906439323474420/libs'] self = <class 'dashboard.ajaxs.GetTraceCodeStatAPI'>: [<dashboard.ajaxs.GetTraceCodeStatAPI object at 0xee8a2f0428db0348>] args = <type 'tuple'>: [()] atts = <type 'dict'>: [{}]
I2011-08-29 21:37:05.206
Login as FB User: <db.models.User object at 0xee8a2f0428cd37c8>
如此一來後台似乎就沒那麼神秘難解了!
延伸閱讀: http://code.google.com/intl/zh-TW/appengine/articles/logging.html
留言
張貼留言