Reputation: 195
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?
Upvotes: 19
Views: 44872
Reputation: 962
Better if we have a short-hand - something like just log("try me") typing the whole console.log() everytime is a painful exercise.
Upvotes: 1
Reputation: 1110
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
Upvotes: 18
Reputation: 46287
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.
Upvotes: 8