Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling and logging #531

Closed
gvilarino opened this issue Dec 29, 2014 · 7 comments
Closed

Improve error handling and logging #531

gvilarino opened this issue Dec 29, 2014 · 7 comments

Comments

@gvilarino
Copy link
Member

We must find a better way to log and handle errors; especially on the backend.

We're currently using debug and we just log stuff, but it might be cool to have some stuff shown through logged to stderr, and to be shown differently (i.e.: more visibly) when something goes wrong. debug supports that (in a way) but you need to set that up whenever you require it.

I think we could wrap debug under a log util and provide a more comfortable api.

Another approach would be to mimic what notifier does, even if we don't make it rely on logentries.

Actually this could be a good thing to make into a module/component under DemocracyOS and have all our repos use that.

Thoughts?

@jfresco
Copy link
Contributor

jfresco commented Jan 29, 2015

You mean to build a wrapper of debug in order to have several verbosity levels? (i.e., error and debug). It could be nice.

I used Minilog a couple of times and liked the API and flexibility. Supports several verbosity levels and output streams. Works on browsers and server-side, but have no Component support.

@alejandro-uliski
Copy link

Hey guys, I added a question to gtter, I think here is a good place to add the same question cause the log in this case is not informative:

I am trying to install DemocracyOS on my ubuntu, I get the following error while running make: error : "no remote found for dependency "component/dropdown@7207a". run component open troubleshooting for help." any idea?

@gvilarino
Copy link
Member Author

@alejandro-uliski that's just an error with the build in your environment; nothing to do with DemocracyOS and thus not on our scope.

@sachalifs
Copy link
Contributor

@alejandro-uliski please refer to this link on our wiki pages

@mjlescano
Copy link
Member

@gvilarino I did this wrapper for another project:

import debug from 'debug'
import config from './config'

let base = 'democracyos'

let logLevels = [
  'critical',
  'error',
  'warn',
  'info',
  'debug',
]

let logLevel = logLevels.indexOf(config.DEBUG)

if (logLevel > -1) {
  let scope = logLevels.slice(0, logLevel + 1)
    .map(l => `${base}:${l},${base}:${l}:*`)
    .join(',')
  debug.enable(scope)
} else if (config.DEBUG === '*') {
  debug.enable(`${base}:*`)
} else if (config.DEBUG) {
  debug.enable(config.DEBUG)
}

export default class Log {
  constructor (scope) {
    logLevels.forEach(level => {
      let baseScope = `${base}:${level}`
      if (scope) baseScope += `:${scope}`
      this[level] = debug(baseScope)
    })
  }
}

The idea is to let you log on different leves (error, warning, etc). And it can be used directly or scoped. The DEBUG variable can be used to configure debug level; e.g.: if you set DEBUG=warn will only show critical,error,warn levels.

Without scope:

import Log from 'lib/log'

let log = new Log()

log.critical('Everything is broken, ahahahahah!')
log.warn('A message that will never be read.')
log.debug('Debugging message')

will print:

democracyos:critical Everything is broken, ahahahahah!
democracyos:warning A message that will never be read.
democracyos:debug Debugging message

Scoped example:

import Log from 'lib/log'

let log = new Log('article:show')

log.critical('Everything is broken in this scope, ahahahahah!')

will print:

democracyos:critical:article:show: "Everything is broken in this scope, ahahahahah!"

@gvilarino
Copy link
Member Author

@mjlescano that's sort of what I have in mind. I'd like to build it on top of visionmedia/debug tho, and with some additional stuff. Let's discuss in person.

@mjlescano
Copy link
Member

Here's a better lib. We can make it configurable to print to stdout and/or .log files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants