调试Asset compute工作程序

asset compute工作程序可以通过多种方式进行调试,从简单的调试日志语句,到作为远程调试器附加的VS Code ,再到为从AEM as a Cloud Service启动的Adobe I/O Runtime中的激活提取日志。

日志记录

最基本的调试Asset compute工作程序使用传统 console.log(..) 工作代码中的语句。 的 console JavaScript对象是隐式的全局对象,因此无需导入或要求导入,因为它始终存在于所有上下文中。

根据Asset compute工作程序的执行方式,这些日志语句可以以不同的方式进行审阅:

  • aio app run,日志将打印为标准输出, 开发工具的 激活日志
    aio app run console.log(...)
  • aio app test,日志打印到 /build/test-results/test-worker/test.log
    aio app test console.log(...)
  • 使用 wskdebug,日志语句将打印到VS代码调试控制台(查看>调试控制台),标准输出
    wskdebug console.log(...)
  • 使用 aio app logs,日志语句将打印到激活日志输出

通过附加的调试器进行远程调试

警告

为了与wskdebug兼容,请使用Microsoft Visual Studio代码1.48.0或更高版本

wsdebug npm模块,支持将调试器附加到Asset compute工作程序,包括能够在VS代码中设置断点并逐步完成代码。

使用wskdebug调试Asset compute工作程序的点进(无音频)

  1. 确保 wsdebug恩格罗克 npm模块已安装

  2. 确保 Docker Desktop和支持Docker映像 安装并运行

  3. 关闭开发工具的任何活动运行实例。

  4. 使用部署最新代码 aio app deploy 和记录已部署的操作名称( [...])。 用于更新 launch.json 中。

    ℹ Info: Deploying package [wkndAemAssetCompute-0.0.1]...
    
  5. 使用命令启动Asset compute开发工具的新实例 npx adobe-asset-compute devtool

  6. 在VS代码中,点按左侧导航中的调试图标

    • 如果出现提示,请点按 创建launch.json文件> Node.js 创建新 launch.json 文件。
    • 否则,点按 齿轮 图标 启动计划 用于打开现有 launch.json 在编辑器中。
  7. 将以下JSON对象配置添加到 configurations 数组:

    {
        "type": "pwa-node",
        "request": "launch",
        "name": "wskdebug",
        "attachSimplePort": 0,
        "runtimeExecutable": "wskdebug",
        "args": [
            "wkndAemAssetCompute-0.0.1/__secured_worker",  // Version must match your Asset Compute worker's version
            "${workspaceFolder}/actions/worker/index.js",  // Points to your worker
            "-l",
            "--ngrok"
        ],
        "localRoot": "${workspaceFolder}",
        "remoteRoot": "/code",
        "outputCapture": "std",
        "timeout": 30000
    }
    
  8. 选择新 wsdebug 从下拉菜单中

  9. 点按绿色 运行 按钮 wsdebug 下拉列表

  10. 打开 /actions/worker/index.js 然后点按行号左侧以添加断点1。 导航到在步骤6中打开的Asset compute开发工具Web浏览器窗口

  11. 点按 运行 用于执行工作程序的按钮

  12. 导航回VS代码,再导航回 /actions/worker/index.js 并逐步完成代码

  13. 要退出可调试的开发工具,请点按 Ctrl-C 在航站楼里 npx adobe-asset-compute devtool 步骤6中的命令

从Adobe I/O Runtime访问日志

AEMas a Cloud Service通过处理用户档案来利用Asset compute工作程序 直接在Adobe I/O Runtime调用。 由于这些调用不涉及本地开发,因此无法使用本地工具(如Asset compute开发工具或wskdebug)来调试其执行。 相反,可以使用Adobe I/OCLI从在Adobe I/O Runtime的特定工作区中执行的工作程序中获取日志。

  1. 确保 特定于工作区的环境变量 通过 AIO_runtime_namespaceAIO_runtime_auth,基于需要调试的工作区。

  2. 从命令行中执行 aio app logs

    • 如果工作区遇到大量流量,请通过 --limit 标记:

      $ aio app logs --limit=25

  3. 最近的(截至提供的 --limit)激活日志将作为命令的输出返回以供审阅。

    aio应用程序日志

疑难解答

在此页面上