node.js - 如何在应用洞察中编写 node js azure 函数日志?
问题描述
我想在 node js azure 函数中执行日志记录,日志应该出现在应用程序洞察力中。
我尝试使用 sdk 并且还检查了应用程序洞察力>实时指标>示例遥测,但是我使用 context.log() 添加的自定义日志没有出现在应用程序地图内的任何地方而不是事件。
那么我还能在哪里查看日志呢?任何人都可以给我任何我可以参考的例子吗?
解决方案
可以参考官方文档。有很多方法可以做到这一点。
官方文档中的示例代码。
let appInsights = require("applicationinsights");
appInsights.setup().start(); // assuming ikey in env var. start() can be omitted to
disable any non-custom data
let client = appInsights.defaultClient;
client.trackEvent({name: "my custom event", properties: {customProperty: "custom
property value"}});
client.trackException({exception: new Error("handled exceptions can be logged with this method")});
client.trackMetric({name: "custom metric", value: 3});
client.trackTrace({message: "trace message"});
client.trackDependency({target:"http://dbname", name:"select customers proc",
data:"SELECT * FROM Customers", duration:231, resultCode:0, success: true,
dependencyTypeName: "ZSQL"});
client.trackRequest({name:"GET /customers", url:"http://myserver/customers", duration:309, resultCode:200, success:true});
let http = require("http");
http.createServer( (req, res) => {
client.trackNodeHttpRequest({request: req, response: res}); // Place at the beginning of your request handler
});
推荐阅读
- html - 有没有办法用 CSS 隐藏没有任何 id 和 class 的特定跨度?
- wordpress - 带有自定义分类的自定义帖子类型的单页不起作用
- python - 为什么即使我安装了 freader 包,python 3.6 中的 freader 模块也会显示错误?
- c# - 在异步调用中强制重新渲染更新面板中的 svg 部分?
- r - 在 R 中创建一个带有序数约束的分类随机向量
- php - UpdateOrCreate 无法更新一列
- c# - 按钮上的绑定命令不起作用 wpf mvvm
- python - 为什么 subprocess 会启动“额外”应用程序?
- c++ - Eclipse C++:致命错误:cheddar.h:没有这样的文件或目录
- css - CSS 模块和悬停 CSS 无法正常工作