一个异步的远程和本地调试工具
tekek的Python项目详细描述
特点
- python内置记录器的半直接替换
- 异步
- 支持Websocket(WIP)
- 可靠的远程记录
- 可靠的文件记录
- 可靠的控制台日志记录
- 高度可配置
安装
Tekek可以通过PyPI您可以使用pip
安装它
python3 -m pip install tekek
导入Tekek
并实例化。在
你好,世界
^{pr2}$默认情况下,tekek提供了7个级别的日志记录
logger.log("MESSAGE")logger.debug("MESSAGE")logger.info("MESSAGE")logger.warning("MESSAGE")logger.error("MESSAGE")logger.exception("MESSAGE")logger.critical("MESSAGE")
基本用法示例:
deffunction_a():logger.log("function a starts !",identifier="function_a")try:...# Some Algorithmlogger.info("finished doing things","function_a")exceptExceptionase:logger.exception("Exception raised {}".format(e),"function_a")logger.debug(identifier="function_a",message="function a finished !")returndeffunction_b():logger.error("this error came from function b","function_a")
是的,它是正则函数,而不是async
函数。为什么?因为Tekek足够聪明,可以为您处理它。别担心,它只会影响应用程序的性能
兼容性示例
三井集团
哦,是的,如果你要快,你需要快速开发它Fast!使用你的调试工具!在
fromsanicimportSanicfromsanic.responseimportjsonfromtekekimportTekekapp=Sanic("sanic_example")logger=Tekek("sanic_example",app=app)@app.route("/",methods=["GET"])asyncdefroot(request):logger.log("root accessed ! hello world!","root")returnjson({"status":"Hello World!"})if__name__=="__main__":app.run(host="0.0.0.0",port=8000)
快速API
一个漂亮的API框架也需要一个漂亮的tekek;)
fromfastapiimportFastAPIfromtekekimportTekekapp=FastAPI()logger=Tekek("my_fast_api",app=app)@app.get("/")asyncdefroot():logger.log("root accessed ! hello world!","root")return{"status":"Hello World!"}
你自己的剧本!
当然你可以使用你自己的应用程序!让我们创建my_app
作为示例
使用coroutine
函数
importasynciofromtekekimportTekeklogger=Tekek("mah_own")asyncdefmy_app(some_param:int):logger.log(f"My App Run Successfully! {some_param}")...# Your Beautiful appreturnTrueasyncdefmain():loop=asyncio.new_event_loop()asyncio.set_event_loop(loop)awaitasyncio.gather(my_app(3),logger.start())if__name__=='__main__':asyncio.run(main())
使用class
importasynciofromtekekimportTekeklogger=Tekek("mah_own")classMyApp:def__init__(self):self.some_vars=3asyncdefapp(self):logger.log(f"App Ran! {self.some_vars}")...# Your beautiful appasyncdefstart(self):asyncio.ensure_future(self.app())my_app=MyApp()asyncdefmain():loop=asyncio.new_event_loop()asyncio.set_event_loop(loop)awaitasyncio.gather(my_app.start(),logger.start())if__name__=='__main__':asyncio.run(main())
真的很好!在
继续阅读:使用文档
- 项目
标签: