Py学习  »  Python

如何避免Python中的默认事件日志记录

Deepak • 5 年前 • 1376 次点击  

我开始在python中使用日志,我想将日志写入文件。

下面是当前正在进行的示例日志记录:


将事件名称从before-call.api gateway更改为before-call.api-gateway
正在从request-created.machinelearning更改事件名称。 预测到请求创建。机器学习。 预测将区域的配置变量设置为“us-west-2”

我如何实例化记录器

logger = logging.getLogger("S3_transfer")

def set_log_output_file(logname):
    if not os.path.exists('logs'):
        os.makedirs('logs')
    logging.basicConfig(filename='logs/{}.log'.format(logname),
                        filemode='a',
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%a, %d %b %Y %H:%M:%S',
                        level=logging.DEBUG)

def get_logger():
    """
    Retrieves the current logger
    :return: Logger
    """
    return logger

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55641
 
1376 次点击  
文章 [ 1 ]  |  最新文章 5 年前