Guest User

Untitled

a guest
Mar 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const isDev = process.env.NODE_ENV === 'development'
  2. const eff = f => x => ((f(x), x))
  3. const noop = () => {}
  4.  
  5. const pad = n => n < 10 ? '0' + n : n
  6.  
  7. const fmtD = d => d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) +
  8. ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds())
  9.  
  10. const now = () => fmtD(new Date())
  11.  
  12. const info = tag => x => {
  13. console.log(`\x1b[34m${now()} ${tag}\x1b[0m`)
  14. console.dir(x, { colors: true })
  15. console.log()
  16. }
  17. const error = tag => e => {
  18. console.error(`\x1b[31m${now()} ${tag}\x1b[0m`)
  19. console.dir(e, { colors: true })
  20. console.log()
  21. }
  22.  
  23. const trace = tag => eff(isDev ? info(tag) : noop)
  24.  
  25. module.exports = { error, info, trace }
Add Comment
Please, Sign In to add comment