Naming Python loggers

后端 未结 3 571
深忆病人
深忆病人 2020-11-30 20:20

In Django, I\'ve got loggers all over the place, currently with hard-coded names.

For module-level logging (i.e., in a module of view functions) I have the urge to d

3条回答
  •  醉酒成梦
    2020-11-30 20:35

    That looks like it will work, except that self won't have a __module__ attribute; its class will. The class-level logger call should look like:

    self.log = logging.getLogger( "%s.%s" % ( self.__class__.__module__, self.__class__.__name__ ) )
    

提交回复
热议问题