Add support for redirecting or disabling messages from stdout to elsewhere.
The newly introduced procedure wiiuse_set_output can be used to set the FILE* used for each of the loglevels LOGLEVEL_ERROR, LOGLEVEL_WARNING, LOGLEVEL_INFO, and LOGLEVEL_DEBUG. Setting the logfile to 0 disables log output for a loglevel. This adds the macro definition WIIUSE_HAS_OUTPUT_REDIRECTION, so programs can test for the feature. The internal log macros in definitions.h all honor this output redirection mechanism.
This commit is contained in:
committed by
Ryan Pavlik
parent
ca4a38c31c
commit
4829592601
23
src/wiiuse.c
23
src/wiiuse.c
@@ -58,6 +58,24 @@ const char* wiiuse_version() {
|
||||
return WIIUSE_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Output FILE stream for each wiiuse_loglevel.
|
||||
*/
|
||||
FILE* logtarget[4];
|
||||
|
||||
/**
|
||||
* @brief Initialize an array of wiimote structures.
|
||||
*
|
||||
* @param loglevel The loglevel, for which the output should be set.
|
||||
*
|
||||
* @param logfile A valid, writeable <code>FILE*</code>, or 0, if output should be disabled.
|
||||
*
|
||||
* The default <code>FILE*</code> for all loglevels is <code>stderr</code>
|
||||
*/
|
||||
void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile)
|
||||
{
|
||||
logtarget[(int)loglevel] = logfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clean up wiimote_t array created by wiiuse_init()
|
||||
@@ -112,6 +130,11 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
g_banner = 1;
|
||||
}
|
||||
|
||||
logtarget[0] = stderr;
|
||||
logtarget[1] = stderr;
|
||||
logtarget[2] = stderr;
|
||||
logtarget[3] = stderr;
|
||||
|
||||
if (!wiimotes)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user