Skip to content

Instantly share code, notes, and snippets.

@greghaygood
Last active August 30, 2016 18:35
Show Gist options
  • Save greghaygood/f21066ce3ab7bd322646a83876de8a32 to your computer and use it in GitHub Desktop.
Save greghaygood/f21066ce3ab7bd322646a83876de8a32 to your computer and use it in GitHub Desktop.
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
    }
    Reactotron.display({
      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)

or

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