2018-04-25 10:19:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) <2018> Intel Corporation
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-09-27 14:00:34 +08:00
|
|
|
#include <stdlib.h>
|
2018-04-25 10:19:46 +08:00
|
|
|
#include <string.h>
|
2018-09-27 14:00:34 +08:00
|
|
|
#include <stdarg.h>
|
2018-04-25 10:19:46 +08:00
|
|
|
#include "log_sys.h"
|
|
|
|
|
2018-09-27 14:00:34 +08:00
|
|
|
void debug_log(const int level, const char *func, const int line, ...)
|
2018-04-25 10:19:46 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *fmt;
|
2018-09-27 14:00:34 +08:00
|
|
|
char *head;
|
|
|
|
char *msg;
|
2018-04-25 10:19:46 +08:00
|
|
|
|
|
|
|
if (level > LOG_LEVEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(args, line);
|
|
|
|
fmt = va_arg(args, char *);
|
|
|
|
if (!fmt)
|
|
|
|
return;
|
2018-09-27 14:00:34 +08:00
|
|
|
if (vasprintf(&msg, fmt, args) == -1)
|
|
|
|
return;
|
2018-04-25 10:19:46 +08:00
|
|
|
va_end(args);
|
|
|
|
|
2018-09-27 14:00:34 +08:00
|
|
|
if (asprintf(&head, "<%-20s%5d>: ", func, line) == -1) {
|
|
|
|
free(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd_journal_print(level, "%s%s", head, msg);
|
|
|
|
free(msg);
|
|
|
|
free(head);
|
2018-04-25 10:19:46 +08:00
|
|
|
}
|