versatica/JsSIP — pull request #123 by jscheid (2013-06-28 14:48:53+00:00)
Title: Use a configurable logger object for all logging

Hi! I'd like to propose this change for inclusion in JsSIP.

It introduces a new configuration option `logger_factory`. This option can be set to a function receiving one argument, `category`, and returning an object with (at least) functions `debug`, `log`, `warn`, and `error`. The semantics of these functions are identical to the corresponding functions in the browser `console` object.

If the `logger_factory` option isn't specified the default is to log using the `console` object, with each log message prefixed by the log category in square brackets. This means that logging will work as before, except that the prefix is formatted differently.

This change makes logging calls more DRY by obviating the need to manually prefix log messages with `LOG_PREFIX`. More importantly, it enables use of third-party logging frameworks such as log4javascript, which in turn is useful for, say, remote logging.

This is obviously a pervasive change. All 253 tests still pass and a smoke test (incl. WebRTC session) works. However, since the tests don't have full coverage I can't be certain it doesn't break anything. If you're willing to accept this patch, please review and test it carefully. I'm happy to improve on it in case you find any remaining issues.