LOG: add an enter and leave trace function

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2011-05-06 10:54:20 +10:00
parent 06642a4227
commit 2a83aa8dfe
3 changed files with 15 additions and 6 deletions

View File

@ -247,8 +247,6 @@ extern struct qb_log_callsite __stop___verbose[];
*/
void qb_log_real_(struct qb_log_callsite *cs, ...);
#define QB_LOG_TAG_EXTERNAL_BIT 30
#define QB_LOG_TAG_EXTERNAL (1 << QB_LOG_TAG_EXTERNAL_BIT)
#define QB_LOG_TAG_LIBQB_MSG_BIT 31
#define QB_LOG_TAG_LIBQB_MSG (1 << QB_LOG_TAG_LIBQB_MSG_BIT)
@ -329,6 +327,10 @@ void qb_log_from_external_source(const char *function,
#else
#define qb_perror
#endif
#define qb_enter() qb_log(LOG_TRACE, "entering %s()", __func__)
#define qb_leave() qb_log(LOG_TRACE, "leaving %s()", __func__)
#define QB_LOG_SYSLOG 0
#define QB_LOG_STDERR 1
#define QB_LOG_BLACKBOX 2

View File

@ -105,12 +105,14 @@ void syslog(int priority, const char *format, ...)
static void log_it_please(void)
{
qb_enter();
qb_log(LOG_TRACE, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_DEBUG, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_INFO, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_NOTICE, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_WARNING, "A:%d B:%d C:%d", 1, 2, 3);
qb_log(LOG_ERR, "A:%d B:%d C:%d", 1, 2, 3);
qb_leave();
}
START_TEST(test_log_basic)

View File

@ -29,8 +29,11 @@
#define MY_TAG_TWO (1 << 1)
#define MY_TAG_THREE (1 << 2)
static void func_one(void) {
static void func_one(void)
{
FILE* fd;
qb_enter();
qb_logt(LOG_DEBUG, MY_TAG_TWO, "arf arf?");
qb_logt(LOG_CRIT, MY_TAG_THREE, "arrrg!");
qb_logt(LOG_ERR, MY_TAG_THREE, "oops, I did it again");
@ -40,13 +43,17 @@ static void func_one(void) {
if (fd == NULL) {
qb_perror(LOG_ERR, "can't open(\"/nothing.txt\")");
}
qb_leave();
}
static void func_two(void) {
static void func_two(void)
{
qb_enter();
qb_logt(LOG_DEBUG, 0, "arf arf?");
qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!");
qb_log(LOG_ERR, "oops, I did it again");
qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ...");
qb_leave();
}
static void show_usage(const char *name)
@ -143,8 +150,6 @@ int32_t main(int32_t argc, char *argv[])
qb_log_tags_stringify_fn_set(my_tags_stringify);
if (do_stderr) {
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FUNCTION, "func_one", LOG_DEBUG);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, __FILE__, priority);
qb_log_format_set(QB_LOG_STDERR, "%4g: %f:%l [%p] %b");