- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想在我的 ionic 应用程序中使用 logentries.com 设置远程日志记录。
package.json
的摘录: "dependencies": {
"bunyan": "^1.8.5",
"bunyan-logentries": "^1.2.0",
},
"devDependencies": {
"@types/bunyan": "0.0.35",
"@types/bunyan-logentries": "0.1.30",
"typescript": "2.0.9"
},
import {createStream} from "bunyan-logentries";
import * as Logger from "bunyan";
// ...
constructor() {
let token = 'xxxxxxxxxxxxxxxxx';
let log = Logger.createLogger({
name: '',
streams: [{
level: 'info',
stream: createStream({token: token}),
type: 'raw'
}]
});
log.info("Created log");
}
我的 IDE 不会警告我任何错误。但一旦我运行该应用程序,我就会收到以下错误:
exists is not a function. (In 'exists(pkgPath)', 'exists' is undefined)
findPackage@http://localhost:8101/build/main.js:131257:18
register@http://localhost:8101/build/main.js:131332:31
http://localhost:8101/build/main.js:112585:50
http://localhost:8101/build/main.js:113391:34
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:129423:37
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:29972:95
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:80592:90
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:59390:96
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:59495:94
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:128048:94
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:116775:92
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:149625:89
__webpack_require__@http://localhost:8101/build/main.js:20:34
http://localhost:8101/build/main.js:66:37
global code@http://localhost:8101/build/main.js:67:12
我认为问题的核心是@types
与实际的 Node 模块不匹配,但目前还不清楚如何解决这个问题。
最佳答案
我也遇到过同样的问题。bunyan-logentries
模块依赖于 le_node
: Node 的 logentries 模块。
le_node
使用浏览器无法使用的 net
和 tls
模块。
为了继续,我实现了一个自定义的 Bunyan 流,它通过 REST API 将日志发送到 logentries 。编码简单且有效。
下面是一个示例代码来说明此解决方案。
创建 Bunyan 实例的 LoggerService:
@Injectable()
export class LoggerService {
constructor(private http: Http) {
}
public create(name: string): Logger{
return Bunyan.createLogger({
name: name,
streams: [{
stream: new LogentriesBunyanStream(AppConfig.LogEntries.token, this.http),
type: 'raw'
}]
});
}
}
将日志发送到logentries的bunyan自定义流:
export class LogentriesBunyanStream extends Writable {
private token: string;
private http: Http;
constructor(token: string, http: Http) {
super({objectMode: true});
this.http = http;
this.token = token;
}
public _write(rec: any, encoding?: string, cb?: Function) {
// Replace the level code with a friendly string
rec.level = LogentriesBunyanStream.resolveLevel(rec.level);
// Send the post request to logentries
// https://docs.logentries.com/docs/http-post
const LOGENTRIES_URL = "https://webhook.logentries.com/noformat/logs/";
let headers = new Headers();
headers.append("Content-Type", 'application/json');
let requestoptions = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: JSON.stringify(rec)
});
this.http.request(LOGENTRIES_URL + this.token, requestoptions).toPromise().then((response) => {
cb();
}).catch((error) =>{
console.log("faield to send log to the logentries server");
});
};
private static resolveLevel(bunyanLevel) {
let levelToName = {
10: 'DEBUG',
20: 'DEBUG',
30: 'INFO',
40: 'WARN',
50: 'ERROR',
60: 'CRIT'
};
return levelToName[bunyanLevel] || 'INFO';
}
};
也许有帮助,
问候。
关于node.js - 使用 Bunyan 和 Logentries 登录 Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42205121/
我有一个带有 heroku 的测试应用程序,并添加了 logentries。 我想知道是否可以从实时尾部过滤掉某些类型的日志,在我的情况下,所有带有“heroku 路由器”术语的日志 最佳答案 只需否
我正在尝试使用 log4net 将一些数据记录到 www.logentries.com。 我的问题是我尝试记录的所有内容都显示在 FileAppender 中,但 logentries.com 上没有
根据LogEntries documentation帐户 key 应填写在 Web.config 文件中。同时存在于 AppHarbor 配置变量中。 我可以从配置变量中读取值而不是使用硬编码值吗?
我正在使用 Wildfly(和 maven)开发 Java Web 应用程序,我想将日志记录与 Logback 一起使用,如 https://logentries.com/doc/java/#logb
如何将 Heroku 的 bash 的控制台输出重定向到 Logentries/其他文件日志? 我使用以下命令: heroku run bash 使用以下命令运行长时间运行的 CasperJS 脚本:
什么是 LogWriter.ShouldLog(..) 方法行为基于?或者它使用的真正意图是什么?它的文档页面相当稀疏,并没有提供太多的洞察力。引用它: Queries whether a LogEn
我最近才知道 django 中内置的 LogEntry 模型,并且我尝试在我的管理页面中注册它。我想要发生的是,例如,管理员添加了新的 User ,而不是使用 django 管理页面,而是通过我在网站
我有一个自定义的 LogEntry 类 - ErrorEntry,它派生自 LogEntry。它有一些公共(public)属性(类对象也是属性之一),我希望在其中放入额外的数据。 public cla
我正在尝试设置一个“logentries”帐户来记录我的 python 开发事件。但即使使用文档中提供的最简单的测试,我也会收到以下错误。有什么想法吗? Python 2.7.10 (default,
我已启用日志导出到 pub sub 主题。我正在使用数据流来处理这些日志并将相关列存储在 BigQuery 中。有人可以帮助将 pubsub 消息有效负载转换为 LogEntry 对象吗?我尝试过以下
我试图弄清楚我经常从 LogEntries 中得到的这些错误是否值得担心。我有一个与 heroku 上的 Rails API 对话的 iPhone 应用程序。我使用 HireFire 自动增加和减少应
我正在开发一个新的 Django 项目并坚持迁移。 我想做一个 UserModel,为了做到这一点,到目前为止我做了两件事。 1.我制作了AuthUser模型并在下面的类中设置了一个Meta类。 在
有没有人有幸让他们的 azure 函数通过 nLog 写入 Logentries?无法在线找到任何示例或文档。我能找到的最接近的是这个示例,但没有考虑 Logentries。 https://gith
我可以通过执行以下操作来查询一种内容类型模式: LogEntry.objects.filter(content_type__model='foo') 但是如果我想要所有具有 content_type
从 Asp.Net Web Api 应用程序(版本 5)内部,我尝试将日志发送到 LogEntries 但不能。使用相同的代码和配置,我可以从本地主机成功发送日志。 这是我用来发送日志的代码(使用 N
我正在尝试弄清楚是否有可能以及如何使用企业库日志记录来实现此功能。 在我当前的代码中,我正在处理这样的异常: exceptionManager.HandleException(ex, "LogExce
我在我的 node.js 项目中使用 pm2 ( https://github.com/Unitech/pm2 )。此外,我还在 Logentries ( https://logentries.com
我正在尝试为 Task Definition on AWS ECS 配置 logentries 如您所见 here “logentries”可用于容器实例。 但是,我找不到有关如何配置它的任何文档或示
我想在我的 ionic 应用程序中使用 logentries.com 设置远程日志记录。 这是我的 package.json 的摘录: "dependencies": { "bunyan"
我正在使用 Rails.logger.error 来记录我的错误。我试图在我的日志和 heroku 的 logentries 插件中查看它们,我看到它们被记录为简单文本。没有迹象表明这实际上是一个错误
我是一名优秀的程序员,十分优秀!