简体   繁体   English

console.log的替代品?

[英]Alternatives to console.log?

I was wondering if there are any alternatives to writing something to the console without using console messages. 我想知道是否有任何替代方法可以在不使用控制台消息的情况下向控制台写入内容。 My project removes all console statements before finalizing the build, but in a unique case I need to find a way to display something to the user via the console. 我的项目在最终构建之前删除了所有控制台语句,但在一个独特的情况下,我需要找到一种通过控制台向用户显示内容的方法。 Is this even possible without console statements? 如果没有控制台声明,这是否可能?

If your build process only touches the console statements in your project and not dependencies, you can try using one of many third-party logging frameworks. 如果构建过程仅触及项目中的console语句而不是依赖项,则可以尝试使用许多第三方日志框架之一。

It is important to note that internally they still call console , and if your build process strips out code of third-party dependencies then I must say that your process requires some changes. 重要的是要注意,在内部他们仍然调用console ,如果你的构建过程剥离出第三方依赖的代码,那么我必须说你的过程需要一些更改。

You can write to console only through Console object. 您只能通过Console对象写入控制台。 The Console object provides access to the browser's debugging console. Console对象提供对浏览器调试控制台的访问。

console.log("Failed to open the specified link")

You can use other methods for debugging: info() 您可以使用其他方法进行调试:info()

console.info('Debug message');

warn() 警告()

console.warn('Debug message');

error() 错误()

console.error('Debug error message')

time() 时间()

console.time(label);

table() 表()

console.table(["apples", "oranges", "bananas"]);

trace() 跟踪()

console.trace();

As for me, I like using console.table() and console.group() 至于我,我喜欢使用console.table()和console.group()

Additional info on the MDN - https://developer.mozilla.org/en-US/docs/Web/API/Console and on the article https://medium.freecodecamp.org/how-to-get-the-most-out-of-the-javascript-console-b57ca9db3e6d 有关MDN的其他信息 - https://developer.mozilla.org/en-US/docs/Web/API/Console和文章https://medium.freecodecamp.org/how-to-get-the-most退房手续的最的JavaScript控制台,b57ca9db3e6d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM