Wrap debug messages in Config.DEBUG checks

This commit is contained in:
Gergely Polonkai 2016-03-05 07:02:39 +00:00
parent 95084b8e93
commit f37d90e468
5 changed files with 83 additions and 36 deletions

View File

@ -295,7 +295,9 @@ public class Matrix.Event : GLib.Object, GLib.Initable {
return klass.get_type(); return klass.get_type();
} }
warning("UsingMatrix.Event for %s", event_type); if (Config.DEBUG) {
warning("Using Matrix.Event for %s", event_type);
}
return typeof(Matrix.Event); return typeof(Matrix.Event);
} }

View File

@ -69,8 +69,10 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
_homeserver = null; _homeserver = null;
_user_id = null; _user_id = null;
if (Config.DEBUG) {
debug("API URL: %s", api_uri.to_string(false)); debug("API URL: %s", api_uri.to_string(false));
debug("Media URL: %s", media_uri.to_string(false)); debug("Media URL: %s", media_uri.to_string(false));
}
} else { } else {
warning("Invalid base URL: %s", value); warning("Invalid base URL: %s", value);
} }
@ -186,7 +188,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
} }
if (token != null) { if (token != null) {
if (Config.DEBUG) {
debug("Adding access token '%s'", token); debug("Adding access token '%s'", token);
}
parms.replace("access_token", token); parms.replace("access_token", token);
} }
@ -208,6 +212,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
request_data = "{}".data; request_data = "{}".data;
} }
if (Config.DEBUG) {
debug("Sending %d bytes (%s %s): %s", debug("Sending %d bytes (%s %s): %s",
request_data.length, request_data.length,
method, method,
@ -215,6 +220,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
(raw_content != null) (raw_content != null)
? "<Binary data>" ? "<Binary data>"
: (string)request_data); : (string)request_data);
}
message.set_flags(Soup.MessageFlags.NO_REDIRECT); message.set_flags(Soup.MessageFlags.NO_REDIRECT);
message.set_request( message.set_request(
@ -276,7 +282,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
} }
if (is_json) { if (is_json) {
if (Config.DEBUG) {
debug("Response (%s): %s", request_url, data); debug("Response (%s): %s", request_url, data);
}
content = parser.get_root(); content = parser.get_root();
@ -290,7 +298,10 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
string? access_token; string? access_token;
if ((access_token = node.get_string()) != null) { if ((access_token = node.get_string()) != null) {
if (Config.DEBUG) {
debug("Got new access token: %s", access_token); debug("Got new access token: %s", access_token);
}
token = access_token; token = access_token;
} }
} }
@ -301,8 +312,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
string? refresh_token; string? refresh_token;
if ((refresh_token = node.get_string()) != null) { if ((refresh_token = node.get_string()) != null) {
if (Config.DEBUG) {
debug("Got new refresh token: %s", debug("Got new refresh token: %s",
refresh_token); refresh_token);
}
this.refresh_token = refresh_token; this.refresh_token = refresh_token;
} }
} }
@ -311,7 +325,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if ((node = root.get_member("home_server")) != null) { if ((node = root.get_member("home_server")) != null) {
string homeserver = node.get_string(); string homeserver = node.get_string();
debug("Our home server calls itself %s", homeserver); if (Config.DEBUG) {
debug("Our home server calls itself %s",
homeserver);
}
this._homeserver = homeserver; this._homeserver = homeserver;
} }
@ -320,7 +338,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if ((node = root.get_member("user_id")) != null) { if ((node = root.get_member("user_id")) != null) {
string user_id = node.get_string(); string user_id = node.get_string();
debug("We are reported to be logged in as %s", user_id); if (Config.DEBUG) {
debug("We are reported to be logged in as %s",
user_id);
}
this._user_id = user_id; this._user_id = user_id;
} }
@ -403,14 +425,21 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if (accept_non_json) { if (accept_non_json) {
raw_content = new ByteArray.sized((uint)datalen); raw_content = new ByteArray.sized((uint)datalen);
raw_content.append(buffer.data); raw_content.append(buffer.data);
debug("Binary data (%s): %u bytes", request_url, (uint)datalen);
if (Config.DEBUG) {
debug("Binary data (%s): %u bytes",
request_url, (uint)datalen);
}
} else { } else {
err = new Matrix.Error.BAD_RESPONSE( err = new Matrix.Error.BAD_RESPONSE(
"Malformed response (invalid JSON)"); "Malformed response (invalid JSON)");
if (Config.DEBUG) {
debug("Malformed response (%s): %s", request_url, data); debug("Malformed response (%s): %s", request_url, data);
} }
} }
} }
}
/* Call the assigned function, if any */ /* Call the assigned function, if any */
if (cb != null) { if (cb != null) {

View File

@ -84,7 +84,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
Matrix.Event evt; Matrix.Event evt;
if (event_node.get_node_type() != Json.NodeType.OBJECT) { if (event_node.get_node_type() != Json.NodeType.OBJECT) {
if (Config.DEBUG) {
warning("Received event that is not an object."); warning("Received event that is not an object.");
}
return; return;
} }
@ -92,7 +94,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
root_obj = event_node.get_object(); root_obj = event_node.get_object();
if ((node = root_obj.get_member("type")) == null) { if ((node = root_obj.get_member("type")) == null) {
if (Config.DEBUG) {
warning("Received event without type."); warning("Received event without type.");
}
return; return;
} }
@ -102,11 +106,15 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
try { try {
evt = Matrix.Event.new_from_json(event_type, room_id, event_node); evt = Matrix.Event.new_from_json(event_type, room_id, event_node);
} catch (Matrix.Error e) { } catch (Matrix.Error e) {
if (Config.DEBUG) {
warning("Error during event creation: %s", e.message); warning("Error during event creation: %s", e.message);
}
return; return;
} catch (GLib.Error e) { } catch (GLib.Error e) {
if (Config.DEBUG) {
warning("Error during event creation: %s", e.message); warning("Error during event creation: %s", e.message);
}
return; return;
} }
@ -143,11 +151,17 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
var root_obj = json_content.get_object(); var root_obj = json_content.get_object();
Json.Node? node; Json.Node? node;
if (Config.DEBUG) {
debug("Processing account data"); debug("Processing account data");
}
_process_event_list_obj(root_obj.get_member("account_data"), _process_event_list_obj(root_obj.get_member("account_data"),
null); null);
if (Config.DEBUG) {
debug("Processing presence"); debug("Processing presence");
}
_process_event_list_obj(root_obj.get_member("presence"), _process_event_list_obj(root_obj.get_member("presence"),
null); null);
@ -156,7 +170,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
Json.Object rooms_object = node.get_object(); Json.Object rooms_object = node.get_object();
Json.Node rooms_node; Json.Node rooms_node;
if (Config.DEBUG) {
debug("Processing rooms"); debug("Processing rooms");
}
if ((rooms_node = rooms_object.get_member( if ((rooms_node = rooms_object.get_member(
"invite")) != null) { "invite")) != null) {

View File

@ -40,8 +40,8 @@ public class Matrix.PresenceEvent : Matrix.Event {
if ((node = content_root.get_member("user_id")) != null) { if ((node = content_root.get_member("user_id")) != null) {
_sender = node.get_string(); _sender = node.get_string();
} else { } else if (Config.DEBUG) {
GLib.warning("user_id is missing from the m.presence event"); warning("user_id is missing from the m.presence event");
} }
if ((node = content_root.get_member("last_active_ago")) != null) { if ((node = content_root.get_member("last_active_ago")) != null) {
@ -67,8 +67,8 @@ public class Matrix.PresenceEvent : Matrix.Event {
} else { } else {
_presence = Matrix.Presence.UNKNOWN; _presence = Matrix.Presence.UNKNOWN;
} }
} else { } else if (Config.DEBUG) {
GLib.warning("presence is missing from the m.presence event"); warning("presence is missing from the m.presence event");
} }
base.from_json(json_data); base.from_json(json_data);

View File

@ -40,14 +40,14 @@ public class Matrix.RoomMemberEvent : Matrix.RoomEvent {
if ((node = root.get_member("state_key")) != null) { if ((node = root.get_member("state_key")) != null) {
_state_key = node.get_string(); _state_key = node.get_string();
} else { } else if (Config.DEBUG) {
GLib.warning("state_key is missing from the m.room.member event"); warning("state_key is missing from the m.room.member event");
} }
if ((node = root.get_member("room_id")) != null) { if ((node = root.get_member("room_id")) != null) {
_room_id = node.get_string(); _room_id = node.get_string();
} else { } else if (Config.DEBUG) {
GLib.warning("room_id is missing from the m.room.member event"); warning("room_id is missing from the m.room.member event");
} }
if ((node = content_root.get_member("membership")) != null) { if ((node = content_root.get_member("membership")) != null) {
@ -58,8 +58,8 @@ public class Matrix.RoomMemberEvent : Matrix.RoomEvent {
if (mship != null) { if (mship != null) {
_membership = mship; _membership = mship;
} }
} else { } else if (Config.DEBUG) {
GLib.warning("membership key is missing from the m.room.member event"); warning("membership key is missing from the m.room.member event");
} }
if ((node = content_root.get_member("avatar_url")) != null) { if ((node = content_root.get_member("avatar_url")) != null) {