Running and Debugging GData Applications
Environment variables
libgdata makes use of a few environment variables which affect how it runs, mainly with respect to debugging.
LIBGDATA_DEBUG
. If this environment variable is set to one of the following values, libgdata will give debug output
(at various levels). If it's unset, no debug output will be produced.
0 |
Output no debug messages or network logs. |
1 |
Output debug messages, but not network logs. |
2 |
Output debug messages and network traffic headers. |
3 |
Output debug messages and full network traffic logs. |
So, to debug a program which uses libgdata, run it from a terminal with the following command:
$
LIBGDATA_DEBUG=3 ./my-program-name &> libgdata.log
Debugging Advice
The easiest way to debug problems with libgdata is to use the
LIBGDATA_DEBUG
environment variable to observe all the network
traffic being transmitted and received by libgdata. Typically, any problems will occur in the final network
request/response, which is the last one in the log output.
If debugging using the environment variables and log output is not possible, it is sometimes possible to diagnose problems
by examining the error responses sent by the Google servers to libgdata. These are exposed as the error messages returned
by libgdata methods; so when handling errors from libgdata method calls, it is a good idea to output the message from
the GError to a debug log, or even as a warning in the user's
.xsession-errors
file.
Example 1. Error Handling when Uploading a Document
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
GDataUploadStream *upload_stream; GError *error = NULL; /* make sure to initialise the GError to NULL */ /* Other code goes here. */ upload_stream = gdata_documents_service_upload_document (service, document, slug, content_type, destination_folder, NULL, &error); /* Handle any errors. */ if (error != NULL) { /* Note that the error message is outputted to the terminal/logs. * It will contain important debugging information from the Google servers. */ g_error ("Error getting upload stream: %s", error->message); g_error_free (error); return; } |