调试Backstage
在本地首次配置 Backstage 或修改新代码时,更改日志记录级别有助于更好地了解系统的运行情况。
Backstage使用Winston logging library并支持的例如warn
,info
(默认值),或debug
.
日志实例也会传递给插件,使它们也能公开其处理信息。
可以通过设置LOG_LEVEL
环境变量。
例如,要在本地运行应用程序时打开调试日志,可以运行
LOG_LEVEL=debug yarn dev
现在,生成的日志中应该有更多可供调试的信息:
[1] 2023-04-12T00:51:42.468Z catalog debug Skipped stitching of domain:default/artists, no changes type=plugin
[1] 2023-04-12T00:51:42.469Z catalog debug Skipped stitching of domain:default/playback, no changes type=plugin
[1] 2023-04-12T00:51:42.470Z catalog debug Processing system:default/podcast type=plugin
[1] 2023-04-12T00:51:42.470Z catalog debug Processing group:default/infrastructure type=plugin
[1] 2023-04-12T00:51:42.470Z catalog debug Processing group:default/boxoffice type=plugin
[1] 2023-04-12T00:51:42.470Z catalog debug Processing group:default/backstage type=plugin
[1] 2023-04-12T00:51:42.470Z catalog debug Processing group:default/team-a type=plugin
[1] 2023-04-12T00:51:42.519Z catalog debug Skipped stitching of group:default/acme-corp, no changes type=plugin
[1] 2023-04-12T00:51:42.520Z catalog debug Skipped stitching of group:default/backstage, no changes type=plugin
[1] 2023-04-12T00:51:42.521Z catalog debug Skipped stitching of group:default/boxoffice, no changes type=plugin
[1] 2023-04-12T00:51:42.523Z catalog debug Processing user:default/breanna.davison type=plugin
[1] 2023-04-12T00:51:42.524Z catalog debug Processing user:default/janelle.dawe type=plugin
[1] 2023-04-12T00:51:42.524Z catalog debug Processing user:default/nigel.manning type=plugin
[1] 2023-04-12T00:51:42.524Z catalog debug Processing user:default/guest type=plugin
[1] 2023-04-12T00:51:42.525Z catalog debug Processing group:default/team-b type=plugin
[1] 2023-04-12T00:51:44.057Z search info Starting collation of explore tools type=plugin
[1] 2023-04-12T00:51:44.095Z backstage info ::1 - - [12/Apr/2023:00:51:44 +0000] "GET /api/explore/tools HTTP/1.1" 200 - "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)" type=incomingRequest
[1] 2023-04-12T00:51:44.100Z backstage info ::1 - - [12/Apr/2023:00:51:44 +0000] "GET /api/catalog/entities?filter=metadata.annotations.backstage.io%2Ftechdocs-ref&fields=kind,namespace,metadata.annotations,metadata.name,metadata.title,metadata.namespace,spec.type,spec.lifecycle,relations&offset=0&limit=500 HTTP/1.1" 200 - "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)" type=incomingRequest
[1] 2023-04-12T00:51:44.104Z search info Finished collation of explore tools type=plugin
[1] 2023-04-12T00:51:44.118Z search info Collating documents for tools succeeded type=plugin documentType=tools
[1] 2023-04-12T00:51:44.119Z backstage debug task: search_index_tools will next occur around 2023-04-11T21:01:44.118-04:00 type=taskManager task=search_index_tools
调试器
VSCode
在您的launch.json
添加一个新条目,内容如下
{
"name": "Start Backend",
"type": "node",
"request": "launch",
"args": [
"package",
"start"
],
"cwd": "${workspaceFolder}/packages/backend",
"program": "${workspaceFolder}/node_modules/.bin/backstage-cli",
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal"
},
WebStorm
本节介绍在 WebStorm 中为 Backstage 启用运行配置的过程。 运行配置可以使用步进器和断点等调试功能。
- Select
Edit Configurations
in theRun
dropdown menu. Click the plus sign to add a new configuration, then selectNode.js
. 2. InWorking directory
, input{PROJECT_DIR}/packages/backend
. Replace{PROJECT_DIR}
with the path to your Backstage repo. 3. InJavaScript file
, input{PROJECT_DIR}/node_modules/@backstage/cli/bin/backstage-cli
. Replace{PROJECT_DIR}
with the path to your Backstage repo. 4. InApplication parameters
, inputpackage start
. 5. Optionally, forEnvironment Variables
, inputLOG_LEVEL=debug
. 6. ClickApply
to save the changes. 7. With the newly-created configuration selected, use theRun
orDebug
icons on the toolbar to execute the newly created configuration.