阿里云函数计算日志记录

阿里云知识 阿里云知识 3年前 (2020-02-18) 182次浏览 0个评论 扫描二维码

阿里云函数计算日志记录
你可以使用日志记录语句在函数中记录函数执行情况,Function会将这些日志写入函数日志,若你使用控制台调用函数,控制台将显示相同日志。你可以在日志服务的对应函数页面查看代码中的函数日志,函数日志配置与查询详情请参见函数日志。

阿里云函数计算地址 https://www.aliyun.com/product/fc
阿里云函数计算官方帮助文档 https://help.aliyun.com/document_detail/52895.html

通过以下 Python 语句生成日志条目:
print 语句
logging 模块中的 Logger 函数

printlogging. 函数将日志写入函数日志中,而 logging. 函数将额外信息写入每个日志条目中,例如时间戳和日志级别。

使用 logging 语句写入日志

你可以通过使用logging模块将信息写入函数日志,示例如下:

import logginglogger = logging.getLogger()logger.setLevel(logging.INFO)def my_logging_handler(event, context): logger.info('got event{}'.format(event)) logger.error('something is error')return 'function is worked'

使用 print 语句写入日志

你可以通过print语句打印函数日志,示例如下:

from __future__ import print_functiondef lambda_handler(event, context): print('it is running')` return 'Hello World!'`

在此示例中,仅将打印文本发送到日志服务。日志条目将不会包含 logging. 函数返回的额外信息。

喜欢 (0)
阿里云最新优惠活动,点击查看
腾讯云最新优惠活动,点击查看
腾讯云香港及海外免备案服务器优惠活动,点击查看
华为云服务器本周优惠活动,点击查看

文章评论已关闭!