Skip to content

Instantly share code, notes, and snippets.

@mcgaffin
Last active March 6, 2019 19:58
Show Gist options
  • Save mcgaffin/cc6716e0ef4faa9ae3f42ddd65c28fc8 to your computer and use it in GitHub Desktop.
Save mcgaffin/cc6716e0ef4faa9ae3f42ddd65c28fc8 to your computer and use it in GitHub Desktop.
Console/Canary Tips

chrome console

colorize your logs

normal log message

console.log('normal log message')

image

log message with color

console.log('%clog message with color', 'color: blue')

image

log message with multiple colors

console.log('%clog message with not one color, %cbut two!', 'color:blue', 'color:red')

image

fully-formatted log message!

console.log('%clog message with background color and padding', 'color:white, background-color:blue, padding: 6px')

image


log objects, not variables

Instead of this:

console.log("This is myValue:", myValue);
=> This is myValue: 3

Do this:

console.log({myValue});
=> {myValue: 3}

Logging multiple values?

console.log({myValue, anotherValueThatIsAlsoMine});
=> {myValue: 3, anotherValueThatIsAlsoMine: "also 3"}

new chrome canary feature -- log points

No need to add console.log statements to your code to log values. Instead:

  1. find your code in the dev console (Sources tab)
  2. right-click the line number
  3. select Add logpoint...
  4. enter the label or value you want to log.
    • if logging a value, enclose it in curly brackets {myValue}
  5. refresh!

ymmv: it's a little tedious to find the right spot in code, right-click, etc., but it saves some cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment