52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding:utf-8 -*-
|
|
#
|
|
# import importlib,sys
|
|
# importlib.reload(sys)
|
|
# sys.setdefaultencoding('utf8')
|
|
|
|
import tornado.web
|
|
import tornado.httpserver
|
|
import tornado.ioloop
|
|
import tornado.options
|
|
import os
|
|
from tornado.options import define, options
|
|
from libs import db_session, engine # import the engine to bind
|
|
#from libs.memcache import cache
|
|
|
|
if os.getenv("ENV")=='dev':
|
|
from dev_settings import url_handlers, settings
|
|
else:
|
|
from settings import url_handlers, settings
|
|
|
|
|
|
|
|
define("port", default=8000, help="run on the given port", type=int)
|
|
|
|
|
|
class Application(tornado.web.Application):
|
|
def __init__(self, handlers, **settings):
|
|
tornado.web.Application.__init__(self, handlers, **settings)
|
|
# Have one global connection. or call:session
|
|
self.db = db_session
|
|
#self.cache = cache
|
|
#self.redis = redis.StrictRedis()
|
|
|
|
application = Application(url_handlers, **settings)
|
|
|
|
if __name__ == "__main__":
|
|
tornado.options.parse_command_line()
|
|
|
|
tornado.options.options.logging = "debug" # 日志等级 "debug|info|warning|error|none"
|
|
tornado.options.options.log_rotate_mode = "time"
|
|
tornado.options.options.log_rotate_when = "D" # 时间单位 "other options:('S', 'M', 'H', 'D', 'W0'-'W6')"
|
|
tornado.options.options.log_rotate_interval = 5 # 间隔
|
|
tornado.options.options.log_file_prefix = "%s.log"%os.path.dirname(os.path.abspath(__file__)) # 文件名
|
|
#tornado.options.options.log_file_prefix = "%s/logs/theLog" % os.path.dirname(os.path.abspath(__file__)) # 文件名
|
|
tornado.options.options.log_file_num_backups = 10 # 间隔
|
|
tornado.options.options.log_to_stderr = True # 输出到屏幕
|
|
|
|
http_server = tornado.httpserver.HTTPServer(application)
|
|
http_server.listen(options.port)
|
|
tornado.ioloop.IOLoop.instance().start()
|