by gjuggler · 13y ago · 0 comments
For using Chrome's logging styles, we define a few short helper functions — l1(), l2(), l3(), etc. — that return predefined CSS strings, then doing our logging like
console.log("%cThis is a heading", l1())
console.log("%cLess important stuff", l2())
This means you're only adding 6 or so characters to get nice styled console messages that also maintain the nice line numbers and links to the source. Plus, it's similar enough to h1, h2, etc. that it's easy to remember.We found that varying the font color (black vs. gray) and margin-left (2em, 4em) were most helpful in differentiating more and less important log messages.
console.assert(str.length === 10, "String is not 10 characters long!");
and console.group/groupEnd console.group("sums");
console.log(1 + 1);
console.log(2 - 3);
console.groupEnd();