Commit d1c6c684 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Improved function nmxp_log()


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@229 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 69eba3bd
......@@ -13,6 +13,22 @@
#define NMXP_LOG_H 1
/*! normal output with time and package name */
#define LOG_NORM 0
/*! error output with time and package name */
#define LOG_ERR 1
/*! warning output with time and package name */
#define LOG_WARN 2
/*! normal output without time and package name */
#define LOG_NORM_NO 3
/*! normal output with only package name */
#define LOG_NORM_PKG 4
/*! \brief A generic logging/printing routine
*
* This function works in two modes:
......@@ -25,7 +41,13 @@
* format, and printf arguments. If the verbosity level is less
* than or equal to the set verbosity (see mode 1), the printf
* format and arguments will be printed at the appropriate log
* level. I.e. 'sl_log(0, 0, "error: %s", result);'
* level, where level represents:
* -# 0, normal output with time and package name
* -# 1, error output with time and package name
* -# 2, warning output with time and package name
* -# 3, normal output without time and package name
* -# 4, normal output with only package name
*
*
* \retval new_verbosity if using mode 1.
* \retval n the number of characters formatted on success, and a
......
......@@ -307,10 +307,10 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_
nmxp_sendTerminateSubscription(naqssock, NMXP_SHUTDOWN_NORMAL, "Good Bye!");
} else {
printf("Error on receiveChannelList()\n");
nmxp_log(1, 0, "Error on receiveChannelList()\n");
}
} else {
printf("Error on sendConnect()\n");
nmxp_log(1, 0, "Error on sendConnect()\n");
}
// 8. Close the socket
......
......@@ -276,7 +276,7 @@ int nmxp_data_log(NMXP_DATA_PROCESS *pd) {
// nmxp_log(0, 0, "%12d %5s.%3s rate=%03d (%s - %s) [%d, %d] pts=%04d (%d, %d, %d, %d) lat=%.1f len=%d\n",
// printf("%10d %5s.%3s 03dHz (%s - %s) lat=%.1fs [%d, %d] pts=%04d (%d, %d, %d, %d) len=%d\n",
printf("%s.%s.%3s %3dHz (%s - %s) lat %.1fs [%d, %d] (%d) %4dpts (%d, %d, %d, %d, %d) %d\n",
nmxp_log(LOG_NORM_NO, 0, "%s.%s.%3s %3dHz (%s - %s) lat %.1fs [%d, %d] (%d) %4dpts (%d, %d, %d, %d, %d) %d\n",
/* pd->key, */
pd->network,
(strlen(pd->station) == 0)? "XXXX" : pd->station,
......@@ -309,7 +309,7 @@ int nmxp_data_log(NMXP_DATA_PROCESS *pd) {
}
*/
} else {
printf("Pointer to NMXP_DATA_PROCESS is NULL!\n");
nmxp_log(1, 0, "Pointer to NMXP_DATA_PROCESS is NULL!\n");
}
return 0;
......
......@@ -50,11 +50,22 @@ int nmxp_log(int level, int verb, ... )
retvalue = vsnprintf(message, MAX_LOG_MESSAGE_LENGTH, format, listptr);
if ( level == 1 ) {
printf("%s - %s: error: %s", timestr, PACKAGE_NAME, message);
}
else {
printf("%s - %s: %s", timestr, PACKAGE_NAME, message);
switch(level) {
case LOG_ERR:
printf("%s - %s: error: %s", timestr, PACKAGE_NAME, message);
break;
case LOG_WARN:
printf("%s - %s: warning: %s", timestr, PACKAGE_NAME, message);
break;
case LOG_NORM_NO:
printf("%s", message);
break;
case LOG_NORM_PKG:
printf("%s: %s", PACKAGE_NAME, message);
break;
default:
printf("%s - %s: %s", timestr, PACKAGE_NAME, message);
break;
}
fflush(stdout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment