logger.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable no-console */
  2. const chalk = require('chalk')
  3. const ip = require('ip')
  4. const divider = chalk.gray('\n-----------------------------------')
  5. /**
  6. * Logger middleware, you can customize it to make messages more personal
  7. */
  8. const logger = {
  9. // Called whenever there's an error on the server we want to print
  10. error: (err) => {
  11. console.error(chalk.red(err))
  12. },
  13. // Called when express.js app starts on given port w/o errors
  14. appStarted: (port, host, tunnelStarted) => {
  15. console.log(`Server started ! ${chalk.green('✓')}`)
  16. // If the tunnel started, log that and the URL it's available at
  17. if (tunnelStarted) {
  18. console.log(`Tunnel initialised ${chalk.green('✓')}`)
  19. }
  20. console.log(`
  21. ${chalk.bold('Access URLs:')}${divider}
  22. Localhost: ${chalk.magenta(`http://${host}:${port}`)}
  23. LAN: ${chalk.magenta(`http://${ip.address()}:${port}`) +
  24. (tunnelStarted
  25. ? `\n Proxy: ${chalk.magenta(tunnelStarted)}`
  26. : '')}${divider}
  27. ${chalk.blue(`Press ${chalk.italic('CTRL-C')} to stop`)}
  28. `)
  29. }
  30. }
  31. module.exports = logger