Skip to content

Instantly share code, notes, and snippets.

@PhoneDroid
Created October 19, 2023 16:02
Show Gist options
  • Select an option

  • Save PhoneDroid/a7bbd0662a62e67cfd13c00a23b5259e to your computer and use it in GitHub Desktop.

Select an option

Save PhoneDroid/a7bbd0662a62e67cfd13c00a23b5259e to your computer and use it in GitHub Desktop.

Console Wrapper

How to properly wrap a console logger function to retain stacktraces.



Simple

Create a logger function that is always prefixed.

export { print }

const print = console.debug.bind(console,'[ Context ]')


Togglable

In case you don't want to always log.

export { print }

const enabled = true

const print = ( enabled )
    ? console.debug.bind(console,'[ Context ]')
    : ( ... _ : Array<any> ) => {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment