transloadit / uppy-server

[DEPRECATED] 'Uppy Server' was renamed to 'Companion' and lives inside the Uppy repo no
https://github.com/transloadit/uppy/tree/master/packages/%40uppy/companion
MIT License
114 stars 27 forks source link

Selfcontained log lines #61

Closed kvz closed 6 years ago

kvz commented 6 years ago

Currently uppy server logs things like:

65536 93365 '70.19%'
93365 93365 '100.00%'
93365 93365 '100.00%'

If we need this log at all, it would be better to use full sentences to describe what is going on. This makes it possible to set up search patterns in the log aggregator, view individual lines without viewing others, set up alerts, etc.

I also noticed that it might be nice to have more logs in general about what is going on, and maybe settle on a prefix like an ISO 8601 date with a syslog severity log level like:

2018-02-07 10:20:21Z [debug] Something uninteresting happened 2018-02-07 10:20:21Z [info] Something slightly interesting happened 2018-02-07 10:20:21Z [notice] Something interesting happened 2018-02-07 10:20:21Z [warning] Something bad could be happening 2018-02-07 10:20:21Z [err] Something bad happened 2018-02-07 10:20:21Z [crit] Something super bad happened 2018-02-07 10:20:21Z [alert] Something super bad happened that (in production) warrants a pagerduty and someone to be woken up 2018-02-07 10:20:21Z [emerg] Something super bad happened that (in production) warrants a pagerduty and someone to be woken up, and the process halts

That's a lot of levels, I'd propose to only pick debug info err emerg from these for starters.

This again helps with setting up graphs and alerts for errors, and e.g. allow to not show debug logs, under which I'd categorize the webserver access logs such as

::ffff:127.0.0.1 - - [07/Feb/2018:10:34:57 +0000] "GET /instagram/authorized HTTP/1.1" 200 22 "http://localhost:3000/dash/uppy.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"

I don't think we need a fancy framework or anything, in the end it's just about writing to the stdout/err. simple log functions will do the trick imho:

  _err (...args) {
    const str = util.format.apply(this, args)
    console.error(`[${this.constructor.name} err]: ${chalk.red(str)}`)
  }

  _info (...args) {
    const str = util.format.apply(this, args)
    console.log(`[${this.constructor.name} info]: ${chalk.dim(str)}`)
  }

  _debug (...args) {
    if (process.env.DEBUG !== 'uppy-server' && `${process.env.DEBUG}`.indexOf('*:*') === -1 && `${process.env.DEBUG}`.indexOf('uppy-server:*') === -1 && `${process.env.DEBUG}`.indexOf(`uppy-server:${this.constructor.name}`) === -1) {
      return
    }
    const str = util.format.apply(this, args)
    console.log(`[${this.constructor.name} debug]: ${chalk.cyan(str)}`)
  }
ifedapoolarewaju commented 6 years ago

generally, uppy-server prepends useful logs with uppy-server using this function https://github.com/transloadit/uppy-server/blob/master/src/uppy.js#L149 Although this is not the case for errors and it should be addressed, the aforementioned log are just left for dev purposes (as uppy-server is not yet stable), and should be removed

ifedapoolarewaju commented 6 years ago

fixed here https://github.com/transloadit/uppy-server/commit/9787a8ce0a0b616b9634856d7364f9d663bd63f2