javascript - is it possible to make an on(consolelog event? it would do something every time text is logged to console
问题描述
This feature would do something every time text is logged to the node.js console. Here's a somewhat of example of how I think it should look like:
on('console', msg => {console.log("text was logged! " + msg)})
Regular node.js
解决方案
Console methods don't emit events, but the console object and its methods can be overwritten, so you could redefine it yourself: console.log = (...args) => { process.stdout.write('logged: ' + args.join(' ')) }
, or wrap it in a Proxy.
推荐阅读
- sql-server - 从查询中检索数据
- raft - TiKV 中的“多筏”是什么?
- hammerdb - HammerDB - 如何使用 mysql、TPCC 模式进行内存测试?
- php - 如何删除 php Cookie
- php - 多次将同一个文件复制到其他文件夹
- python - 查找列表中最小的整数,其中既有字符串又有整数
- android - Android 操作系统不支持非基线 AVC 视频配置文件
- operating-system - 是否需要将实时线程绑定到 LWP?
- wso2 - WSO2:MQTT 输入事件适配器未在侦听
- python - 在没有 Redis 的情况下使用 celery 4