logging: Add deprecation warning for updateSettings

and also use the Strophe.LogLevel levels for logging in general.
This commit is contained in:
JC Brand 2017-07-05 11:33:55 +02:00
parent f81a94baf1
commit 5ab1693136
11 changed files with 66 additions and 34 deletions

View File

@ -775,7 +775,8 @@
_converse.chatboxes.onMessage(msg);
expect(_converse.log).toHaveBeenCalledWith(
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource", "info");
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource",
Strophe.LogLevel.INFO);
expect(_converse.chatboxes.getChatBox).not.toHaveBeenCalled();
_converse.filter_by_resource = false;
@ -819,7 +820,7 @@
_converse.chatboxes.onMessage(msg);
expect(_converse.log.calledWith(
"onMessage: Ignoring incoming headline message sent with type 'chat' from JID: localhost",
"info"
Strophe.LogLevel.INFO
)).toBeTruthy();
expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();

View File

@ -289,7 +289,7 @@
},
onBookmarkError: function (iq) {
_converse.log("Error while trying to add bookmark", "error");
_converse.log("Error while trying to add bookmark", Strophe.LogLevel.ERROR);
_converse.log(iq);
// We remove all locally cached bookmarks and fetch them
// again from the server.
@ -345,7 +345,7 @@
onBookmarksReceivedError: function (deferred, iq) {
window.sessionStorage.setItem(this.cached_flag, true);
_converse.log('Error while fetching bookmarks');
_converse.log('Error while fetching bookmarks', Strophe.LogLevel.ERROR);
_converse.log(iq);
if (!_.isNil(deferred)) {
return deferred.reject();

View File

@ -705,7 +705,7 @@
try {
this.model.destroy();
} catch (e) {
_converse.log(e);
_converse.log(e, Strophe.LogLevel.ERROR);
}
this.remove();
_converse.emit('chatBoxClosed', this);

View File

@ -144,16 +144,21 @@
} else {
logger = console;
}
if (_converse.debug) {
if (level === 'error') {
logger.log('ERROR: '+txt);
} else {
logger.log(txt);
if (level === Strophe.LogLevel.ERROR) {
logger.log('ERROR: '+txt);
} else if (level === Strophe.LogLevel.WARN) {
logger.log('WARNING: '+txt);
} else if (level === Strophe.LogLevel.FATAL) {
logger.log('FATAL: '+txt);
} else if (_converse.debug) {
if (level === Strophe.LogLevel.DEBUG) {
logger.log('DEBUG: '+txt);
} else if (level === Strophe.LogLevel.INFO) {
logger.log('INFO: '+txt);
}
}
};
_converse.initialize = function (settings, callback) {
"use strict";
settings = !_.isUndefined(settings) ? settings : {};
@ -184,7 +189,7 @@
// Logging
Strophe.log = function (level, msg) { _converse.log(level+' '+msg, level); };
Strophe.error = function (msg) { _converse.log(msg, 'error'); };
Strophe.error = function (msg) { _converse.log(msg, Strophe.LogLevel.ERROR); };
// Add Strophe Namespaces
Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2');
@ -657,7 +662,9 @@
.c('enable', {xmlns: Strophe.NS.CARBONS});
this.connection.addHandler(function (iq) {
if (iq.querySelectorAll('error').length > 0) {
_converse.log('ERROR: An error occured while trying to enable message carbons.');
_converse.log(
'An error occured while trying to enable message carbons.',
Strophe.LogLevel.ERROR);
} else {
this.session.save({carbons_enabled: true});
_converse.log('Message carbons have been enabled.');
@ -1133,7 +1140,7 @@
}.bind(this),
function (err) {
alert(__("Sorry, there was an error while trying to add "+name+" as a contact."));
_converse.log(err);
_converse.log(err, Strophe.LogLevel.ERROR);
deferred.resolve(err);
}
);
@ -1583,7 +1590,7 @@
if (_converse.filter_by_resource && (to_resource && to_resource !== _converse.resource)) {
_converse.log(
'onMessage: Ignoring incoming message intended for a different resource: '+to_jid,
'info'
Strophe.LogLevel.INFO
);
return true;
} else if (utils.isHeadlineMessage(message)) {
@ -1592,7 +1599,7 @@
// wrong type ('chat'), so we need to filter them out here.
_converse.log(
"onMessage: Ignoring incoming headline message sent with type 'chat' from JID: "+from_jid,
'info'
Strophe.LogLevel.INFO
);
return true;
}
@ -1658,7 +1665,8 @@
};
} else if (!_converse.allow_non_roster_messaging) {
_converse.log('Could not get roster item for JID '+bare_jid+
' and allow_non_roster_messaging is set to false', 'error');
' and allow_non_roster_messaging is set to false',
Strophe.LogLevel.ERROR);
return;
}
return this.create(_.assignIn({
@ -2166,7 +2174,15 @@
_converse.whitelisted_plugins);
_converse.pluggable.initializePlugins({
'updateSettings': _converse.api.settings.update,
'updateSettings': function () {
_converse.log(
"(DEPRECATION) "+
"The `updateSettings` method has been deprecated. "+
"Please use `_converse.api.settings.update` instead.",
Strophe.LogLevel.WARN
)
_converse.api.settings.update.apply(_converse, arguments);
},
'_converse': _converse
}, whitelist, _converse.blacklisted_plugins);
_converse.emit('pluginsInitialized');
@ -2298,7 +2314,7 @@
'open': function (jids, attrs) {
var chatbox;
if (_.isUndefined(jids)) {
_converse.log("chats.open: You need to provide at least one JID", "error");
_converse.log("chats.open: You need to provide at least one JID", Strophe.LogLevel.ERROR);
return null;
} else if (_.isString(jids)) {
chatbox = _converse.getViewForChatBox(

View File

@ -90,7 +90,8 @@
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log(
"Attempted to fetch archived messages but this "+
"user's server doesn't support XEP-0313");
"user's server doesn't support XEP-0313",
Strophe.LogLevel.WARN);
return;
}
if (this.disable_mam) {
@ -107,7 +108,7 @@
this.clearSpinner();
_converse.log(
"Error or timeout while trying to fetch "+
"archived messages", "error");
"archived messages", Strophe.LogLevel.ERROR);
}.bind(this)
);
},
@ -171,7 +172,8 @@
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log(
"Attempted to fetch archived messages but this "+
"user's server doesn't support XEP-0313");
"user's server doesn't support XEP-0313",
Strophe.LogLevel.WARN);
return;
}
if (!this.model.get('mam_enabled')) {
@ -191,7 +193,7 @@
that.clearSpinner();
_converse.log(
"Error while trying to fetch archived messages",
"error");
Strophe.LogLevel.WARN);
}
);
}
@ -308,9 +310,13 @@
_converse.onMAMError = function (iq) {
if ($(iq).find('feature-not-implemented').length) {
_converse.log("Message Archive Management (XEP-0313) not supported by this browser");
_converse.log(
"Message Archive Management (XEP-0313) not supported by this server",
Strophe.LogLevel.WARN);
} else {
_converse.log("An error occured while trying to set archiving preferences.");
_converse.log(
"An error occured while trying to set archiving preferences.",
Strophe.LogLevel.ERROR);
_converse.log(iq);
}
};

View File

@ -2689,7 +2689,9 @@
} else if (_.isObject(room)) {
_converse.api.rooms.open(room.jid, room.nick);
} else {
_converse.log('Invalid room criteria specified for "auto_join_rooms"', 'error');
_converse.log(
'Invalid room criteria specified for "auto_join_rooms"',
Strophe.LogLevel.ERROR);
}
});
};

View File

@ -148,7 +148,7 @@
if (_.isUndefined(_converse.roster)) {
_converse.log(
"Could not send notification, because roster is undefined",
"error");
Strophe.LogLevel.ERROR);
return;
}
roster_item = _converse.roster.get(from_jid);

View File

@ -351,7 +351,7 @@
} else {
this.showHelpMessages(['Encryption error occured: '+msg], 'error');
}
_converse.log("OTR ERROR:"+msg);
_converse.log("OTR ERROR:"+msg, Strophe.LogLevel.ERROR);
},
startOTRFromToolbar: function (ev) {

View File

@ -304,7 +304,10 @@
Strophe.Status.CONFLICT
], status)) {
_converse.log('Problem during registration: Strophe.Status is: '+status);
_converse.log(
'Problem during registration: Strophe.Status is: '+status,
Strophe.LogLevel.ERROR
);
this.cancelRegistration();
if (error) {
this.giveFeedback(error, 'error');
@ -534,7 +537,7 @@
this.fields[_var.toLowerCase()] = $(field).children('value').text();
} else {
// TODO: other option seems to be type="fixed"
_converse.log("WARNING: Found field we couldn't parse");
_converse.log("Found field we couldn't parse", Strophe.LogLevel.WARN);
}
}.bind(this));
this.form_type = 'xform';
@ -554,7 +557,7 @@
query = query[0];
}
if (stanza.getAttribute("type") === "error") {
_converse.log("Registration failed.");
_converse.log("Registration failed.", Strophe.LogLevel.ERROR);
error = stanza.getElementsByTagName("error");
if (error.length !== 1) {
_converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, "unknown");

View File

@ -671,7 +671,7 @@
}.bind(this),
function (err) {
alert(__("Sorry, there was an error while trying to remove "+name+" as a contact."));
_converse.log(err);
_converse.log(err, Strophe.LogLevel.ERROR);
}
);
}

View File

@ -42,7 +42,10 @@
bare_jid,
_.partial(_converse.createRequestingContactFromVCard, presence),
function (iq, jid) {
_converse.log("Error while retrieving vcard for "+jid);
_converse.log(
"Error while retrieving vcard for "+jid,
Strophe.LogLevel.ERROR
);
_converse.createRequestingContactFromVCard(presence, iq, jid);
}
);
@ -148,7 +151,8 @@
},
function () {
_converse.log(
"updateVCardForChatBox: Error occured while fetching vcard"
"updateVCardForChatBox: Error occured while fetching vcard",
Strophe.LogLevel.ERROR
);
}
);