POSIX: Improved logging

The warnx and warn calls map to PX4_WARN.
Calls to errx or err genrtate a compile error.

The px4_log.h file implements a new log format:

For DEBUG and INFO:
<level> <msg>

For ERROR and WARN:
<level> <msg> (file filepath line linenum)

The verbosity can be changed by setting the macro to use
either linux_log or linux_log_verbose in px4_log.h

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-05-19 09:19:24 -07:00
parent 791d780bb8
commit ffdc9d629c
17 changed files with 161 additions and 120 deletions
@@ -1331,7 +1331,7 @@ info()
return 1;
}
PX4_DBG("state @ %p", g_dev);
PX4_DEBUG("state @ %p", g_dev);
//g_dev->print_info();
return 0;
+45 -46
View File
@@ -250,7 +250,7 @@ int
BAROSIM::init()
{
int ret;
PX4_WARN("BAROSIM::init");
debug("BAROSIM::init");
ret = VDev::init();
if (ret != OK) {
@@ -401,59 +401,58 @@ BAROSIM::ioctl(device::file_t *filp, int cmd, unsigned long arg)
{
switch (cmd) {
case SENSORIOCSPOLLRATE: {
switch (arg) {
case SENSORIOCSPOLLRATE:
switch (arg) {
/* switching to manual polling */
case SENSOR_POLLRATE_MANUAL:
stop_cycle();
_measure_ticks = 0;
return OK;
/* external signalling not supported */
case SENSOR_POLLRATE_EXTERNAL:
/* zero would be bad */
case 0:
return -EINVAL;
/* set default/max polling rate */
case SENSOR_POLLRATE_MAX:
case SENSOR_POLLRATE_DEFAULT: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* set interval for next measurement to minimum legal value */
_measure_ticks = USEC2TICK(BAROSIM_CONVERSION_INTERVAL);
/* if we need to start the poll state machine, do it */
if (want_start)
start_cycle();
/* switching to manual polling */
case SENSOR_POLLRATE_MANUAL:
stop_cycle();
_measure_ticks = 0;
return OK;
}
/* external signalling not supported */
case SENSOR_POLLRATE_EXTERNAL:
/* adjust to a legal polling interval in Hz */
default: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* zero would be bad */
case 0:
return -EINVAL;
/* convert hz to tick interval via microseconds */
unsigned ticks = USEC2TICK(1000000 / arg);
/* set default/max polling rate */
case SENSOR_POLLRATE_MAX:
case SENSOR_POLLRATE_DEFAULT: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* check against maximum rate */
if ((long)ticks < USEC2TICK(BAROSIM_CONVERSION_INTERVAL))
return -EINVAL;
/* set interval for next measurement to minimum legal value */
_measure_ticks = USEC2TICK(BAROSIM_CONVERSION_INTERVAL);
/* update interval for next measurement */
_measure_ticks = ticks;
/* if we need to start the poll state machine, do it */
if (want_start)
start_cycle();
/* if we need to start the poll state machine, do it */
if (want_start)
start_cycle();
return OK;
}
/* adjust to a legal polling interval in Hz */
default: {
/* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0);
/* convert hz to tick interval via microseconds */
unsigned ticks = USEC2TICK(1000000 / arg);
/* check against maximum rate */
if ((long)ticks < USEC2TICK(BAROSIM_CONVERSION_INTERVAL))
return -EINVAL;
/* update interval for next measurement */
_measure_ticks = ticks;
/* if we need to start the poll state machine, do it */
if (want_start)
start_cycle();
return OK;
}
return OK;
}
}
@@ -205,16 +205,16 @@ BARO_SIM::transfer(const uint8_t *send, unsigned send_len,
PX4_DEBUG("BARO_SIM measurement requested");
}
else if (send_len != 1 || send[0] != 0 || recv_len != 3) {
PX4_WARN("BARO_SIM::transfer invalid param %u %u %u\n", send_len, send[0], recv_len);
PX4_WARN("BARO_SIM::transfer invalid param %u %u %u", send_len, send[0], recv_len);
return 1;
}
else {
Simulator *sim = Simulator::getInstance();
if (sim == NULL) {
PX4_ERR("Error BARO_SIM::transfer no simulator \n");
PX4_ERR("Error BARO_SIM::transfer no simulator");
return -ENODEV;
}
PX4_DEBUG("BARO_SIM::transfer getting sample\n");
PX4_DEBUG("BARO_SIM::transfer getting sample");
sim->getBaroSample(recv, recv_len);
}
return 0;
@@ -669,11 +669,11 @@ GYROSIM::transfer(uint8_t *send, uint8_t *recv, unsigned len)
}
else if (cmd & DIR_READ)
{
PX4_DBG("Reading %u bytes from register %u", len-1, reg);
PX4_DEBUG("Reading %u bytes from register %u", len-1, reg);
memcpy(&_regdata[reg-MPUREG_PRODUCT_ID], &send[1], len-1);
}
else {
PX4_DBG("Writing %u bytes to register %u", len-1, reg);
PX4_DEBUG("Writing %u bytes to register %u", len-1, reg);
if (recv)
memcpy(&recv[1], &_regdata[reg-MPUREG_PRODUCT_ID], len-1);
}
@@ -350,7 +350,7 @@ ToneAlarm::start_note(unsigned note)
// Silence warning of unused var
do_something(period);
PX4_DBG("ToneAlarm::start_note %u", period);
PX4_DEBUG("ToneAlarm::start_note %u", period);
}
void
@@ -83,9 +83,9 @@ static void *entry_adapter ( void *ptr )
data->entry(data->argc, data->argv);
free(ptr);
PX4_DBG("Before px4_task_exit");
PX4_DEBUG("Before px4_task_exit");
px4_task_exit(0);
PX4_DBG("After px4_task_exit");
PX4_DEBUG("After px4_task_exit");
return NULL;
}
@@ -231,7 +231,7 @@ void px4_task_exit(int ret)
PX4_ERR("px4_task_exit: self task not found!");
}
else {
PX4_DBG("px4_task_exit: %s", taskmap[i].name.c_str());
PX4_DEBUG("px4_task_exit: %s", taskmap[i].name.c_str());
}
pthread_exit((void *)(unsigned long)ret);
@@ -241,7 +241,7 @@ int px4_task_kill(px4_task_t id, int sig)
{
int rv = 0;
pthread_t pid;
PX4_DBG("Called px4_task_kill %d", sig);
PX4_DEBUG("Called px4_task_kill %d", sig);
if (id < PX4_MAX_TASKS && taskmap[id].pid != 0)
pid = taskmap[id].pid;
@@ -271,3 +271,18 @@ void px4_show_tasks()
PX4_INFO(" No running tasks");
}
__BEGIN_DECLS
const char *getprogname()
{
pthread_t pid = pthread_self();
for (int i=0; i<PX4_MAX_TASKS; i++)
{
if (taskmap[i].isused && taskmap[i].pid == pid)
{
return taskmap[i].name.c_str();
}
}
return "Unknown App";
}
__END_DECLS
+18 -11
View File
@@ -44,6 +44,8 @@ __BEGIN_DECLS
extern void qurt_log(const char *fmt, ...);
__END_DECLS
#include <stdio.h>
#define qurt_log(...) {printf(__VA_ARGS__); printf("\n");}
#define PX4_DBG(...) qurt_log(__VA_ARGS__)
#define PX4_DEBUG(...) qurt_log(__VA_ARGS__)
@@ -52,18 +54,23 @@ __END_DECLS
#define PX4_ERR(...) { qurt_log("ERROR file %s line %d:", __FILE__, __LINE__); qurt_log(__VA_ARGS__); }
#elif defined(__PX4_LINUX)
#include <stdio.h>
#if defined(__PX4_LINUX)
#include <err.h>
#else
#include <systemlib/err.h>
#endif
#define PX4_DBG(...)
#define PX4_DEBUG(...)
#define PX4_INFO(...) warnx(__VA_ARGS__)
#define PX4_WARN(...) warnx(__VA_ARGS__)
#define PX4_ERR(...) { warnx("ERROR file %s line %d:", __FILE__, __LINE__); warnx(__VA_ARGS__); }
#define linux_log(level, ...) { \
printf("%-5s ", level);\
printf(__VA_ARGS__);\
printf("\n");\
}
#define linux_log_verbose(level, ...) { \
printf("%-5s ", level);\
printf(__VA_ARGS__);\
printf(" (file %s line %d)\n", __FILE__, __LINE__);\
}
//#define PX4_DEBUG(...) { }
#define PX4_DEBUG(...) { linux_log("DEBUG", __VA_ARGS__); }
#define PX4_INFO(...) { linux_log("INFO", __VA_ARGS__); }
#define PX4_WARN(...) { linux_log_verbose("WARN", __VA_ARGS__); }
#define PX4_ERR(...) { linux_log_verbose("ERROR", __VA_ARGS__); }
#elif defined(__PX4_ROS)
@@ -264,7 +264,7 @@ void px4_show_tasks()
for (idx=0; idx < PX4_MAX_TASKS; idx++)
{
if (taskmap[idx].isused) {
PX4_INFO(" %-10s %u", taskmap[idx].name.c_str(), taskmap[idx].pid);
PX4_INFO(" %-10s %lu", taskmap[idx].name.c_str(), taskmap[idx].pid);
count++;
}
}