JsSIP
JsSIP copied to clipboard
New Feature: allow to override debugerror
Use Case
I need to intercept the logs from both errors and standard debug log messages, e.g. for sending them to a backend.
Logging standard messages is easy by overriding the debug.log function, e.g. as shown here: https://groups.google.com/g/jssip/c/5LWejj-N_sU, i.e.
JsSIP.debug.log = (...args) => {
const logString = args[0].replace(/%c/g, ''); // Remove coloring syntax used by debug tool.
logger(logString);
};
Logging debugerror is however impossible, since it's internally defined and bound to console.warn() in an isolated scope.
E.g. like in this commit, or here in the sources
var debugerror = require('debug')('JsSIP:ERROR:Socket');
debugerror.log = console.warn.bind(console);
Because of this implementation, exposing the debug module as it's done here is not enough.
Proposal
Have an option for overriding the default logger(s), with default to the current behaviour.
I can try a PR if you like this idea.