Skip to content

Logger #4

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
699 changes: 372 additions & 327 deletions dist/jssip.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jssip.min.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions lib/Dialog.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const Logger = require('./Logger');
const SIPMessage = require('./SIPMessage');
const JsSIP_C = require('./Constants');
const Transactions = require('./Transactions');
const Dialog_RequestSender = require('./Dialog/RequestSender');
const Utils = require('./Utils');
const debug = require('debug')('JsSIP:Dialog');

const logger = new Logger('Dialog');

const C = {
// Dialog states.
@@ -85,7 +87,7 @@ module.exports = class Dialog
}

this._ua.newDialog(this);
debug(`new ${type} dialog created with status ${this._state === C.STATUS_EARLY ? 'EARLY': 'CONFIRMED'}`);
logger.debug(`new ${type} dialog created with status ${this._state === C.STATUS_EARLY ? 'EARLY': 'CONFIRMED'}`);
}

get id()
@@ -127,7 +129,7 @@ module.exports = class Dialog
{
this._state = C.STATUS_CONFIRMED;

debug(`dialog ${this._id.toString()} changed to CONFIRMED state`);
logger.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`);

if (type === 'UAC')
{
@@ -138,7 +140,7 @@ module.exports = class Dialog

terminate()
{
debug(`dialog ${this._id.toString()} deleted`);
logger.debug(`dialog ${this._id.toString()} deleted`);
this._ua.destroyDialog(this);
}

27 changes: 13 additions & 14 deletions lib/DigestAuthentication.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const Logger = require('./Logger');
const Utils = require('./Utils');
const debug = require('debug')('JsSIP:DigestAuthentication');
const debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication');

debugerror.log = console.warn.bind(console);
const logger = new Logger('DigestAuthentication');

module.exports = class DigestAuthentication
{
@@ -35,7 +34,7 @@ module.exports = class DigestAuthentication
return this._ha1;

default:
debugerror('get() | cannot get "%s" parameter', parameter);
logger.warn('get() | cannot get "%s" parameter', parameter);

return undefined;
}
@@ -58,7 +57,7 @@ module.exports = class DigestAuthentication
{
if (this._algorithm !== 'MD5')
{
debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');

return false;
}
@@ -70,14 +69,14 @@ module.exports = class DigestAuthentication

if (!this._nonce)
{
debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
logger.warn('authenticate() | challenge without Digest nonce, authentication aborted');

return false;
}

if (!this._realm)
{
debugerror('authenticate() | challenge without Digest realm, authentication aborted');
logger.warn('authenticate() | challenge without Digest realm, authentication aborted');

return false;
}
@@ -88,15 +87,15 @@ module.exports = class DigestAuthentication
// If ha1 is not provided we cannot authenticate.
if (!this._credentials.ha1)
{
debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');

return false;
}

// If the realm does not match the stored realm we cannot authenticate.
if (this._credentials.realm !== this._realm)
{
debugerror('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm);
logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm);

return false;
}
@@ -116,7 +115,7 @@ module.exports = class DigestAuthentication
else
{
// Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');

return false;
}
@@ -166,7 +165,7 @@ module.exports = class DigestAuthentication
a2 = `${this._method}:${this._uri}`;
ha2 = Utils.calculateMD5(a2);

debug('authenticate() | using qop=auth [a2:"%s"]', a2);
logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2);

// Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${ha2}`);
@@ -178,7 +177,7 @@ module.exports = class DigestAuthentication
a2 = `${this._method}:${this._uri}:${Utils.calculateMD5(body ? body : '')}`;
ha2 = Utils.calculateMD5(a2);

debug('authenticate() | using qop=auth-int [a2:"%s"]', a2);
logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2);

// Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${ha2}`);
@@ -190,13 +189,13 @@ module.exports = class DigestAuthentication
a2 = `${this._method}:${this._uri}`;
ha2 = Utils.calculateMD5(a2);

debug('authenticate() | using qop=null [a2:"%s"]', a2);
logger.debug('authenticate() | using qop=null [a2:"%s"]', a2);

// Response = MD5(HA1:nonce:HA2).
this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${ha2}`);
}

debug('authenticate() | response generated');
logger.debug('authenticate() | response generated');

return true;
}
42 changes: 42 additions & 0 deletions lib/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const debug = require('debug');

const APP_NAME = 'JsSIP';

module.exports = class Logger
{
constructor(prefix)
{
if (prefix)
{
this._debug = debug.default(`${APP_NAME}:${prefix}`);
this._warn = debug.default(`${APP_NAME}:WARN:${prefix}`);
this._error = debug.default(`${APP_NAME}:ERROR:${prefix}`);
}
else
{
this._debug = debug.default(APP_NAME);
this._warn = debug.default(`${APP_NAME}:WARN`);
this._error = debug.default(`${APP_NAME}:ERROR`);
}
/* eslint-disable no-console */
this._debug.log = console.info.bind(console);
this._warn.log = console.warn.bind(console);
this._error.log = console.error.bind(console);
/* eslint-enable no-console */
}

get debug()
{
return this._debug;
}

get warn()
{
return this._warn;
}

get error()
{
return this._error;
}
};
12 changes: 7 additions & 5 deletions lib/Message.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const EventEmitter = require('events').EventEmitter;
const Logger = require('./Logger');
const JsSIP_C = require('./Constants');
const SIPMessage = require('./SIPMessage');
const Utils = require('./Utils');
const RequestSender = require('./RequestSender');
const Exceptions = require('./Exceptions');
const debug = require('debug')('JsSIP:Message');

const logger = new Logger('Message');

module.exports = class Message extends EventEmitter
{
@@ -249,11 +251,11 @@ module.exports = class Message extends EventEmitter

_failed(originator, response, cause)
{
debug('MESSAGE failed');
logger.debug('MESSAGE failed');

this._close();

debug('emit "failed"');
logger.debug('emit "failed"');

this.emit('failed', {
originator,
@@ -264,11 +266,11 @@ module.exports = class Message extends EventEmitter

_succeeded(originator, response)
{
debug('MESSAGE succeeded');
logger.debug('MESSAGE succeeded');

this._close();

debug('emit "succeeded"');
logger.debug('emit "succeeded"');

this.emit('succeeded', {
originator,
12 changes: 6 additions & 6 deletions lib/Parser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Logger = require('./Logger');
const Grammar = require('./Grammar');
const SIPMessage = require('./SIPMessage');
const debugerror = require('debug')('JsSIP:ERROR:Parser');

debugerror.log = console.warn.bind(console);
const logger = new Logger('Parser');

/**
* Parse SIP Message
@@ -15,7 +15,7 @@ exports.parseMessage = (data, ua) =>

if (headerEnd === -1)
{
debugerror('parseMessage() | no CRLF found, not a SIP message');
logger.warn('parseMessage() | no CRLF found, not a SIP message');

return;
}
@@ -26,7 +26,7 @@ exports.parseMessage = (data, ua) =>

if (parsed === -1)
{
debugerror(`parseMessage() | error parsing first line of SIP message: "${firstLine}"`);
logger.warn(`parseMessage() | error parsing first line of SIP message: "${firstLine}"`);

return;
}
@@ -62,7 +62,7 @@ exports.parseMessage = (data, ua) =>
// Data.indexOf returned -1 due to a malformed message.
else if (headerEnd === -1)
{
debugerror('parseMessage() | malformed message');
logger.warn('parseMessage() | malformed message');

return;
}
@@ -71,7 +71,7 @@ exports.parseMessage = (data, ua) =>

if (parsed !== true)
{
debugerror('parseMessage() |', parsed.error);
logger.warn('parseMessage() |', parsed.error);

return;
}
Loading