简体   繁体   中英

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.

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.

You can write to console only through Console object. The Console object provides access to the browser's debugging console.

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

You can use other methods for debugging: 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()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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