mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-05 15:11:35 +08:00
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:
+18
-11
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user