application.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:fluiddb 作者: fluidinfo 项目源码 文件源码
def setupLogging(stream=None, path=None, level=None, format=None):
    """Setup logging.

    Either a stream or a path can be provided.  When a path is provided a log
    handler that works correctly with C{logrotate} is used.  Generally
    speaking, C{stream} should only be used for non-file streams that don't
    need log rotation.

    @param name: The name of the logger to setup.
    @param stream: The stream to write output to.
    @param path: The path to write output to.
    @param level: Optionally, the log level to set on the logger.  Default is
        C{logging.INFO}.
    @param format: A format string for the logger.
    @raise RuntimeError: Raised if neither C{stream} nor C{path} are provided,
        or if both are provided.
    @return: The configured logger, ready to use.
    """
    if (not stream and not path) or (stream and path):
        raise RuntimeError('A stream or path must be provided.')
    if stream:
        handler = StreamHandler(stream)
    else:
        handler = WatchedFileHandler(path)

    if format is None:
        format = '%(asctime)s %(levelname)8s  %(message)s'

    formatter = Formatter(format)
    handler.setFormatter(formatter)
    log = getLogger()
    log.addHandler(handler)
    log.propagate = False
    log.setLevel(level or INFO)
    return log
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号