Logging control

Don't log anything by default, and let the applications change the log
level.
This commit is contained in:
Daniel Drake 2008-11-20 17:23:04 +00:00
parent 29044d9ca9
commit 7c44c86d4c
7 changed files with 68 additions and 3 deletions

View file

@ -115,6 +115,7 @@ int main(void)
fprintf(stderr, "Failed to initialize libfprint\n");
exit(1);
}
fp_set_debug(3);
discovered_devs = fp_discover_devs();
if (!discovered_devs) {

View file

@ -47,6 +47,7 @@ int main(void)
fprintf(stderr, "Failed to initialize libfprint\n");
exit(1);
}
fp_set_debug(3);
discovered_devs = fp_discover_devs();
if (!discovered_devs) {

View file

@ -146,6 +146,7 @@ int main(void)
fprintf(stderr, "Failed to initialize libfprint\n");
exit(1);
}
fp_set_debug(3);
discovered_devs = fp_discover_devs();
if (!discovered_devs) {

View file

@ -91,6 +91,7 @@ int main(void)
fprintf(stderr, "Failed to initialize libfprint\n");
exit(1);
}
fp_set_debug(3);
discovered_devs = fp_discover_devs();
if (!discovered_devs) {

View file

@ -134,6 +134,7 @@ int main(void)
fprintf(stderr, "Failed to initialize libfprint\n");
exit(1);
}
fp_set_debug(3);
discovered_devs = fp_discover_devs();
if (!discovered_devs) {

View file

@ -20,12 +20,16 @@
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <libusb.h>
#include "fp_internal.h"
static int log_level = 0;
static int log_level_fixed = 0;
libusb_context *fpi_usb_ctx = NULL;
GSList *opened_devices = NULL;
@ -41,13 +45,13 @@ GSList *opened_devices = NULL;
* designed so that you only have to do this once - by integrating your
* software with libfprint, you'll be supporting all the fingerprint readers
* that we have got our hands on. As such, the API is rather general (and
* therefore hopefully easy to comprehend!), and does it's best to hide the
* therefore hopefully easy to comprehend!), and does its best to hide the
* technical details that required to operate the hardware.
*
* This documentation is not aimed at developers wishing to develop and
* contribute fingerprint device drivers to libfprint.
*
* Feedback on this API and it's associated documentation is appreciated. Was
* Feedback on this API and its associated documentation is appreciated. Was
* anything unclear? Does anything seem unreasonably complicated? Is anything
* missing? Let us know on the
* <a href="http://www.reactivated.net/fprint/Mailing_list">mailing list</a>.
@ -284,6 +288,15 @@ void fpi_log(enum fpi_log_level level, const char *component,
FILE *stream = stdout;
const char *prefix;
#ifndef ENABLE_DEBUG_LOGGING
if (!log_level)
return;
if (level == LOG_LEVEL_WARNING && log_level < 2)
return;
if (level == LOG_LEVEL_INFO && log_level < 3)
return;
#endif
switch (level) {
case LOG_LEVEL_INFO:
prefix = "info";
@ -826,6 +839,44 @@ API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev)
return fpi_imgdev_get_img_height(imgdev);
}
/** \ingroup core
* Set message verbosity.
* - Level 0: no messages ever printed by the library (default)
* - Level 1: error messages are printed to stderr
* - Level 2: warning and error messages are printed to stderr
* - Level 3: informational messages are printed to stdout, warning and error
* messages are printed to stderr
*
* The default level is 0, which means no messages are ever printed. If you
* choose to increase the message verbosity level, ensure that your
* application does not close the stdout/stderr file descriptors.
*
* You are advised to set level 3. libfprint is conservative with its message
* logging and most of the time, will only log messages that explain error
* conditions and other oddities. This will help you debug your software.
*
* If the LIBFPRINT_DEBUG environment variable was set when libfprint was
* initialized, this function does nothing: the message verbosity is fixed
* to the value in the environment variable.
*
* If libfprint was compiled without any message logging, this function does
* nothing: you'll never get any messages.
*
* If libfprint was compiled with verbose debug message logging, this function
* does nothing: you'll always get messages from all levels.
*
* \param ctx the context to operate on, or NULL for the default context
* \param level debug level to set
*/
API_EXPORTED void fp_set_debug(int level)
{
if (log_level_fixed)
return;
log_level = level;
libusb_set_debug(fpi_usb_ctx, level);
}
/** \ingroup core
* Initialise libfprint. This function must be called before you attempt to
* use the library in any way.
@ -833,6 +884,7 @@ API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev)
*/
API_EXPORTED int fp_init(void)
{
char *dbg = getenv("LIBFPRINT_DEBUG");
int r;
fp_dbg("");
@ -840,7 +892,14 @@ API_EXPORTED int fp_init(void)
if (r < 0)
return r;
libusb_set_debug(fpi_usb_ctx, 3);
if (dbg) {
log_level = atoi(dbg);
if (log_level) {
log_level_fixed = 1;
libusb_set_debug(fpi_usb_ctx, log_level);
}
}
register_drivers();
fpi_poll_init();
return 0;

View file

@ -297,6 +297,7 @@ void fp_set_pollfd_notifiers(fp_pollfd_added_cb added_cb,
/* Library */
int fp_init(void);
void fp_exit(void);
void fp_set_debug(int level);
/* Asynchronous I/O */