博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Loggers in Python
阅读量:6244 次
发布时间:2019-06-22

本文共 2315 字,大约阅读时间需要 7 分钟。

  1. Loggers will send to stderr by default. So make sure stderr has a receiver.

Logger manager

Loggers will be stored in manager in Python. Handlers will cause resource leak if not removed.

def getLogger(name=None):    """    Return a logger with the specified name, creating it if necessary.    If no name is specified, return the root logger.    """    if name:        return Logger.manager.getLogger(name)    else:        return rootclass Manager(object):    def getLogger(self, name):        """        Get a logger with the specified name (channel name), creating it        if it doesn't yet exist. This name is a dot-separated hierarchical        name, such as "a", "a.b", "a.b.c" or similar.        If a PlaceHolder existed for the specified name [i.e. the logger        didn't exist but a child of it did], replace it with the created        logger and fix up the parent/child references which pointed to the        placeholder to now point to the logger.        """        rv = None        if not isinstance(name, basestring):            raise TypeError('A logger name must be string or Unicode')        if isinstance(name, unicode):            name = name.encode('utf-8')        _acquireLock()        try:            if name in self.loggerDict:                rv = self.loggerDict[name]                if isinstance(rv, PlaceHolder):                    ph = rv                    rv = (self.loggerClass or _loggerClass)(name)                    rv.manager = self                    self.loggerDict[name] = rv                    self._fixupChildren(ph, rv)                    self._fixupParents(rv)            else:                rv = (self.loggerClass or _loggerClass)(name)                rv.manager = self                self.loggerDict[name] = rv                self._fixupParents(rv)        finally:            _releaseLock()        return rv

Loggers in Python are stored in Logger.manager with a specified name. If create a logger with a task rather than a file, loggers stored in manager will increase and never be deleted.

It becomes even worse when the logger has a handler, eg. write logs to database. It may cause a connections leak.

Log emit will hang if stderr is not received

Log info will send to stderr by default, make sure stderr buffer has a removed, otherwise stream write will be blocked.

转载地址:http://fpvia.baihongyu.com/

你可能感兴趣的文章
HDU-1213-How Many Tables
查看>>
奇怪的道路[JXOI2012]
查看>>
Windows+MyEclipse+MySQL【连接数据库报错caching_sha2_password】
查看>>
导入数据
查看>>
UMeditor上传图片配置
查看>>
Homestead小结
查看>>
2015年iOS开发总结
查看>>
CocoaPods 安装与使用
查看>>
学习笔记:查最大内存
查看>>
javascript设计模式与开发实践(二)- 封装和原型模式
查看>>
1475: 方格取数
查看>>
太阳黑子
查看>>
[转载]date命令时间转换
查看>>
适配iOS11新特性代码在Xcode8 上编译通过的方法
查看>>
别再问什么是Java内存模型了,看这里!
查看>>
2014.5.7—20岁这几年
查看>>
javac - Java programming language compiler
查看>>
异常处理
查看>>
Python多线程程序中的MYSQL连接管理研究
查看>>
Prometheus学习系列(七)之名词解析
查看>>