如何禁用三个通知消息?

Mil*_*lav 2 three.js objloader

我想禁用 console.log 之类的THREE.WebGLRenderer: Context LostOBJLoader: 1.8330078125ms等等。你有什么建议吗?

The*_*m01 5

除了OBJLoader2.setLogging.

像这样的消息对于调试非常有用,不仅在您的开发环境中,而且在您的代码在现场时也是如此。

但是,如果您很难消除这些消息,则可以重定向使用该console对象的日志记录。

// Place this at the start of your code
const log = console.log;
console.log = () => {};
const warn = console.warn;
console.warn = () => {};
const error = console.error;
console.error = () => {};
Run Code Online (Sandbox Code Playgroud)

有了这个,任何调用console.log,console.warn和 的东西console.error都会被静音,即使es6是主文件范围之外的模块。这甚至适用于控制台消息管理器,如debug.

但是您仍然可以使用重定向函数写入控制台。例如:

// In your code...
log("test message"); // will print "test message" to the console
Run Code Online (Sandbox Code Playgroud)

这只是因为您将原始函数的引用保存到像const log.