Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reactotron debug logger

I wanted an easier way to format debug data for Reactotron that would render more easily, so I came up with this code snippet:

if (__DEV__) {
  console.tlog = (name, mainVal, ...otherVals) => {
    let vars = {_name: name, ...otherVals}
    if (typeof mainVal === 'object') {
      vars = {...vars, ...mainVal}
    } else {
      vars['_mainVal'] = mainVal
      name: 'APP DEBUG',
      preview: name,
      value: vars
} else {
  console.tlog = () => false

This lets me call it in a couple of different ways depending on what i need to show:

console.tlog('i got some data!', dataValue)


console.tlog('i got a bunch of data!', {dataBit1: somethingSomething, dataBit2: somethingElseSomething}

or in a few cases:

console.tlog('i got a bunch of data but one main bit!', theMainSomething, {otherBit11: somethingSomething, otherBit2: somethingElseSomething}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment