在tornado 里面这样用
看看logging.warning() , logging.info() , 我们非常想用 zdaemon , 和 logging 将对系统的所有访问转换到服务器里面,作为日志。
让我们看看目录树。
transaction.py 是tornado服务
看一下 testpage1handler
@require_basic_auth class TestPage1Handler(BaseHandler): """This is a test page to show the asker‘s utmost parent‘s all details """ def post(self, **kwargs): print "hi" logging.info(self.request) a = self.request #print a print type(a) print dir(a) print a.arguments print type(a.arguments) logging.warning(‘Watch out!‘) # will print a message to the console logging.info(‘I told you so‘) # will not print anything ret = {‘ret‘:‘0‘,‘msg‘:‘‘} #name_queue = get_outersystem_org(kwargs) parent_asker = kwargs[‘a‘] #boss_profile = db.get("SELECT * from kms_outersystem where username=%s", parent_asker) boss_profile = db.query("SELECT * FROM kms_sgroup") ret[‘result‘] = { parent_asker : boss_profile } self.write(json_dumps(ret)) return
看看我们add route 的URL
class Application(tornado.web.Application): def __init__(self): handlers = [ # 测试 torndb 效率 (r"/testpage1", TestPage1Handler), # 测试 #(r"/update/dealer/profile", UpdateProfileHandler) #(r"") ] settings = dict( cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", debug=True, ) tornado.web.Application.__init__(self, handlers, **settings) def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application(),no_keep_alive=True) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()
看看我们设置的 transaction.conf 文档,
<runner> program python /somewhere/transaction.py --log_file_prefix=transaction.txt socket-name /somewhere/transaction.zdsock forever true </runner> <environment> LD_LIBRARY_PATH /somewhere HOME /somewhere
</environment> <eventlog> <logfile> path /somewhere/transaction_daemon.log </logfile> </eventlog>
然后,我们在终端使用这个命令。
生成的文件类型:
我们来看一下访问以后,文件变化
____timeline Now 2014 Jan 21st_____