用于对库方法调用进行负责任的低模板日志记录的工具包

logfur的Python项目详细描述


logfury是针对python库维护人员的。它允许对方法调用进行负责任的低模板日志记录。

许可证

BSD 3条款

奇怪的导入是什么

fromlogfury.v0_1importDefaultTraceMeta

如果要在库中使用logfury,对api的任何更改都可能会破坏程序。没人想要。

由于这个导入技巧,我可以保持0.1.x api非常稳定。同时,我可以更改库的功能并更改0.2.x版等的默认行为,而不必更改包的名称。这样,您就可以决定何时采用可能不兼容的api更改,方法是在导入时递增api版本。

安装

电流稳定

pip install logfury

开发版本

git clone git@github.com:ppolewicz/logfury.git
python setup.py install

基本用法

DefaultTraceMeta元类

>>> importlogging>>> importsix>>>
>>> fromlogfury.v0_1importDefaultTraceMeta,limit_trace_arguments,disable_trace>>>
>>>
>>> logging.basicConfig()>>> logger=logging.getLogger(__name__)>>> logger.setLevel(logging.DEBUG)>>>
>>>
>>> @six.add_metaclass(DefaultTraceMeta)>>> classFoo(object):... defbaz(self,a,b,c=None):... returnTrue... defget_blah(self):... return5... def_hello(self):... pass... @disable_trace... defworld(self):... pass... def__repr__(self):... return'<%s object>'%(self.__class__.__name__,)...>>> classBar(Foo):... defbaz(self,a,b,c=None):... b+=1... returnsuper(Bar,self).baz(a,b,c)... defworld(self):... pass... @limit_trace_arguments(skip=['password'])... defsecret(self,password,other):... pass... @limit_trace_arguments(only=['other'])... defsecret2(self,password,other):... pass...>>> a=Foo()>>> a.baz(1,2,3)DEBUG:__main__:calling Foo.baz(self=<Foo object>, a=1, b=2, c=3)
>>> a.baz(4,b=8)DEBUG:__main__:calling Foo.baz(self=<Foo object>, a=4, b=8)
>>> a.get_blah()# nothing happens, since v0_1.DefaultTraceMeta does not trace "get_.*">>> a._hello()# nothing happens, since v0_1.DefaultTraceMeta does not trace "_.*">>> a.world()# nothing happens, since v0_1.DefaultTraceMeta does not trace "_.*">>> b=Bar()>>> b.baz(4,b=8)# tracing is inheritedDEBUG:__main__:calling Bar.baz(self=<Bar object>, a=4, b=8)
DEBUG:__main__:calling Foo.baz(self=<Bar object>, a=4, b=9, c=None)
>>> b.world()# nothing happens, since Foo.world() tracing was disabled and Bar inherited it>>> b.secret('correct horse battery staple','Hello world!')DEBUG:__main__:calling Bar.secret(self=<Bar object>, other='Hello world!') (hidden args: password)
>>> b.secret2('correct horse battery staple','Hello world!')DEBUG:__main__:calling Bar.secret2(other='Hello world!') (hidden args: self, password)

跟踪调用decorator

>>> importlogging>>> fromlogfuryimport*>>> logging.basicConfig()>>> logger=logging.getLogger(__name__)>>>
>>> @trace_call(logger)... deffoo(a,b,c=None):... returnTrue...>>> foo(1,2,3)True
>>> logger.setLevel(logging.DEBUG)>>> foo(1,2,3)DEBUG:__main__:calling foo(a=1, b=2, c=3)
True
>>> foo(1,b=2)DEBUG:__main__:calling foo(a=1, b=2)
True
>>>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring安全编程授权   java Android库AAR取决于另一个库   Java/Groovy双精度语句问题   爪哇。查看安卓监视器图形时,release()不会减少我的内存   java无法在子类中使用EventFiringWebDriver对象   java第一个if语句始终为true,但第二个if语句不为true   java如何从作为字符串提供的XML源代码创建可绘制(或XmlResourceParser对象)?   多线程Java并发问题锁和同步方法   java Android Studio注册链接   java ArrayList of ArrayList of String   使用Shadow重新定位的包中的java Kotlin属性不起作用   java在接口org上找不到方法。阿帕奇。伊巴蒂斯。遗嘱执行人。陈述名为prepare的语句处理程序   如何在Java中放大2倍?   java当参数作为RequestBody和RequestParam发送时,sprig控制器无法识别发送的请求