1.1 KiB
Raw Blame History

title
云函数历史日志

{{ $frontmatter.title }}

:::warning 只有在云函数中加 console 打印才会保存日志! :::

云函数的全部历史日志,全部都自动保存到了日志板块中,日志会保留 3 天

可根据请求 ID requestId 和云函数名筛选

function-log

1、点击日志切换到日志板块

2、可根据 requestId 和云函数名搜索指定日志

3、点击单个日志可查看详细内容

手动清理日志

Laf 云函数的运行日志都在一个隐藏的集合中:__function_logs__

所以我们可以通过云函数操作数据库的方法,清理日志

以下是清理全部日志的云函数写法:

::: danger 以下操作会删除全部历史日志,请谨慎操作 :::

import cloud from '@lafjs/cloud'

export async function main(ctx: FunctionContext) {
  console.log('Hello World')
  // 数据库,删除全部日志
  const db = cloud.database();
  const res = await db.collection('__function_logs__').remove({multi:true})
  console.log(res)
}