mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Enable diagnostic logging from libdivecomputer.
Signed-off-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
badce21b24
commit
60d85de292
1 changed files with 30 additions and 0 deletions
|
@ -679,26 +679,56 @@ static const char *do_device_import(device_data_t *data)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
|
||||||
|
{
|
||||||
|
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
|
||||||
|
|
||||||
|
FILE *fp = (FILE *) userdata;
|
||||||
|
|
||||||
|
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
|
||||||
|
fprintf(fp, "%s: %s [in %s:%d (%s)]\n", loglevels[loglevel], msg, file, line, function);
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "%s: %s\n", loglevels[loglevel], msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char *do_libdivecomputer_import(device_data_t *data)
|
const char *do_libdivecomputer_import(device_data_t *data)
|
||||||
{
|
{
|
||||||
dc_status_t rc;
|
dc_status_t rc;
|
||||||
const char *err;
|
const char *err;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
|
||||||
import_dive_number = 0;
|
import_dive_number = 0;
|
||||||
first_temp_is_air = 0;
|
first_temp_is_air = 0;
|
||||||
data->device = NULL;
|
data->device = NULL;
|
||||||
data->context = NULL;
|
data->context = NULL;
|
||||||
|
|
||||||
|
/* TODO: Enable logging from the UI somehow. */
|
||||||
|
/* TODO: Should the filename (and directory) be configurable? */
|
||||||
|
fp = fopen("subsurface.log", "w");
|
||||||
|
|
||||||
rc = dc_context_new(&data->context);
|
rc = dc_context_new(&data->context);
|
||||||
if (rc != DC_STATUS_SUCCESS)
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
return translate("gettextFromC","Unable to create libdivecomputer context");
|
return translate("gettextFromC","Unable to create libdivecomputer context");
|
||||||
|
|
||||||
|
if (fp) {
|
||||||
|
dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL);
|
||||||
|
dc_context_set_logfunc(data->context, logfunc, fp);
|
||||||
|
}
|
||||||
|
|
||||||
err = translate("gettextFromC","Unable to open %s %s (%s)");
|
err = translate("gettextFromC","Unable to open %s %s (%s)");
|
||||||
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
if (rc == DC_STATUS_SUCCESS) {
|
||||||
err = do_device_import(data);
|
err = do_device_import(data);
|
||||||
|
/* TODO: Show the logfile to the user on error. */
|
||||||
dc_device_close(data->device);
|
dc_device_close(data->device);
|
||||||
}
|
}
|
||||||
dc_context_free(data->context);
|
dc_context_free(data->context);
|
||||||
|
|
||||||
|
if (fp) {
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue