{ "info": { "author": "WeiJi Hsiao", "author_email": "weiji.hsiao@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Typhoon is a wrapper around the [Tornado](https://www.tornadoweb.org/en/stable/) web framework. It offers the ability to attach log records with a trace id, which is used to trace individual HTTP requests. By default Typhoon obtains trace id from the request's header `X-TRACEID`. To change this behavior, subclass `typhoon.web.Application` and overwrite the `get_trace_id` method.\n\n## Requirements\n- tornado >= 5.1\n \n## Installation\n- Use pip:\n ```\n pip install typhoon-web\n pip install typhoon-web --upgrade\n ```\n- Clone repository and install with:\n ```\n python setup.py install\n ```\n\n## Hello, world\n\nHere is a simple \u201cHello, world\u201d example web app for Typhoon:\n```python\nimport logging\nimport time\n\nimport tornado.ioloop\nimport typhoon.web\nimport typhoon.log\n\nclass MainHandler(typhoon.web.RequestHandler):\n @typhoon.web.run_in_executor\n def process(self):\n logging.info('go to sleep')\n time.sleep(3)\n logging.info('wake up')\n return 'Hello, world'\n\n async def get(self):\n result = await self.process()\n self.write(result)\n \n # Native coroutine (using async def and await) was introduced in Python 3.5.\n # For previous version, use generator-based coroutine. \n # For example:\n #\n # @tornado.gen.coroutine\n # def get(self):\n # result = yield self.process()\n # self.write(result)\n\ndef make_app():\n return typhoon.web.Application([\n (r'/', MainHandler),\n ])\n\nif __name__ == '__main__':\n typhoon.log.configure(log_path='/home/logs')\n app = make_app()\n app.listen(8888)\n tornado.ioloop.IOLoop.current().start()\n```\nIn this example, three different log files will be generated in the log_path:\n- **access.log** records summaries of each http request.\n- **stats.log** records messages for statistics and analysis.\n- **app.log** contains all logs that are neither access logs nor stats logs.\n\nTo log to stats.log, use an instance of `typhoon.log.StatsLogger`:\n```python\nimport typhoon.log\n\nstats_log = typhoon.log.StatsLogger()\n\nstats_log.info({'user_count': 100})\nstats_log.info({'job_register': 20}, topic='register')\n```\nNotice that logging methods of `StatsLogger` only accept a `dict` object as message.\n\n## Trace id\nBy default trace id is automatically obtained and handled by Typhoon only when the client sends a request with a header `X-TRACEID: some-value`:\n```bash\n$ curl -H \"X-TRACEID: ceon1haa6cau1dung1\" http://127.0.0.1:8888\n```\n\nTo customize the way trace id is passed, subclass `typhoon.web.Application` and overwrite the `get_trace_id` method.\n```python\nimport typhoon.web\n\nclass MyApplication(typhoon.web.Application):\n def get_trace_id(self, handler):\n # obtain trace id from URL Parameter.\n return handler.get_argument('traceId', '-')\n```\nIn the above example, trace id is passed through an URL parameter:\n```bash\n$ curl http://127.0.0.1:8888?traceId=ceon1haa6cau1dung1\n```\n\nYou may have to call another service and pass down the trace id. In this case, use `typhoon.log.TRACE_ID()` to obtain current trace id:\n```python\nimport requests\nimport typhoon.web\nimport typhoon.log\n\nclass MainHandler(typhoon.web.RequestHandler):\n @typhoon.web.run_in_executor\n def process(self):\n # call another service and pass down current trace id.\n r = request.get('http://127.0.0.1:9990/hello', header={'X-TRACEID': typhoon.log.TRACE_ID()})\n if r.status_code == 200:\n return 'Hello, world'\n else:\n return 'oops!'\n\n async def get(self):\n result = await self.process()\n self.write(result)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/WeiJiHsiao/typhoon", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "typhoon-web", "package_url": "https://pypi.org/project/typhoon-web/", "platform": "", "project_url": "https://pypi.org/project/typhoon-web/", "project_urls": { "Homepage": "https://github.com/WeiJiHsiao/typhoon" }, "release_url": "https://pypi.org/project/typhoon-web/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "A wrapper around the Tornado web framework that supports logs with traceId.", "version": "0.3.0" }, "last_serial": 5883059, "releases": { "0.3.0": [ { "comment_text": "", "digests": { "md5": "b93527e375920cf581c63e24b12fb430", "sha256": "120477f15ceb8f99c53e8c264b0319b4f8427941493ca2ca1557370ea9f6db32" }, "downloads": -1, "filename": "typhoon-web-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b93527e375920cf581c63e24b12fb430", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6653, "upload_time": "2019-09-25T03:35:29", "url": "https://files.pythonhosted.org/packages/70/5e/66f5170f8f5fb23d694a1610db71ddde7a9ab4e87e0a07325466b26b13d6/typhoon-web-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b93527e375920cf581c63e24b12fb430", "sha256": "120477f15ceb8f99c53e8c264b0319b4f8427941493ca2ca1557370ea9f6db32" }, "downloads": -1, "filename": "typhoon-web-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b93527e375920cf581c63e24b12fb430", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6653, "upload_time": "2019-09-25T03:35:29", "url": "https://files.pythonhosted.org/packages/70/5e/66f5170f8f5fb23d694a1610db71ddde7a9ab4e87e0a07325466b26b13d6/typhoon-web-0.3.0.tar.gz" } ] }